Implement a function create_stack

Assignment Help Computer Engineering
Reference no: EM133368802

Question: Create two files, a double_stack.h and a double_stack_list.c . The H file should contain the specification for the stack data type, but nothing about the implementation itself. Implementation should instead be in the C file. In order to encapsulate (hide) the implementation, you must declare the following in the H file:

typedef struct double_stack_struct double_stack;

So we say that the type double_stack should be the same as a type called struct double_stack_struct . However, this is an incomplete data type, because we have only declared it and not said what the struct actually contains! But as long as we only handle pointers to double_stack, it doesn't matter. However, we will not be able to dereference such a pointer, except in the code located in double_stack_list.c .

You get to write down the actual implementation of the struct double_stack_structi C file:

struct double_stack_struct{
/***/
};

To be able to encapsulate the actual implementation, you need to implement a function create_stack that creates an empty stack. This is so that the user does not have to know which data structure the stack uses internally. Because outside of the file double_stack_list.c you cannot use the incomplete type, but only pointers to it, we must in this way give the user a pointer that he can use. This function thus constitutes a kind of "stack factory" (or constructor), which outputs a pointer to a new empty stack, which the person who wants to use the stack can work with. Let the function have the following prototype:

double_stack*create_stack();

This function should therefore create empty list, and return a pointer to it. For it to work, the list must be created dynamically (on the heap), i.e. with malloc . Otherwise, the list created in the function would automatically disappear after the function exits, and the pointer we get back would not be valid anymore. In other words, create double_stack * stack = malloc( sizeof( double_stack ) ); and return that pointer.

Test that you can build a small test program that uses your code, and just includes double_stack.h and creates  new double_stack* using create_stack.???????

#include "double.stack.h"
int main(int argc, char *argv[]){
double_stack*stack;
stack = creat_stack();
return 0;

This program should be able to compile, even if it produces no visible output when run.

Implement the push function to put new elements on the stack.
int push(double_stack*stack, double d);

This function thus takes a pointer to a (possibly empty) stack and a number as input. It should return 1 if everything went well, and 0 otherwise.

Now your test program might look like this.
#include "double_stack.h"
int main(int argc, char *argv[]){
double_stack*stack;
stack = creat_stack(); //empty stack
push(stack,1); //now the stack contains 1
push(stack,2); //now the stack contains 2,1
return 0;
}

also implement the function pop
int pop(double_stack*stack, double*d);

???????which removes the top element from the stack and puts it where d points to. The function should also return 1 if everything went well, and 0 if it failed to pop (if the stack was empty).

Now in your double_stack.h you have a complete interface for a stack containing floating-point numbers, with all the necessary functions. Finally, create a test program that puts some numbers (taking them as arguments via argv as before) into a stack, and then pops them one by one and prints them, each on a new line.

./task 1 2 3 4 5
5.0000
4.0000
3.0000
2.0000

1.10000

Reference no: EM133368802

Questions Cloud

Effects of selective hunting on bighorn sheep : A key part of this effort is setting minimum size for harvesting, such as a minimum antler size in deer or a minimum horn size in wild sheep.
Specify the range of n for which each would be suitable : COSC 2320 University of Houston One has a computing time given by 3^n and that for the other is n^4. Specify the range of n for which each would be suitable
Explain to jack and debbie why powers of attorney : Explain to Jack and Debbie why Powers of Attorney, personal care, and property, are extremely important to this couple. When explaining each, please reference
Applied at international scale : Explain how von Thunen's agricultural land-use model could be applied at the international scale.
Implement a function create_stack : Implement a function create_stack that creates an empty stack. This is so that the user does not have to know which data structure the stack uses
Explain how this is possible and create an example : Your advisor informs you that if you don't add any money or make any changes, then it will take more than 20% recovery just to bring your account back to even.
About black market or underground in Egypt : Write an essay outlining about black market or underground in Egypt. What is the product or service?
Focus on language and religion : Compare them to the evangelizing process by the Jesuits to the colonizing practices of the Spanish and Portuguese. Focus on language and religion
Define the struct medicine that has the components : Define the struct Medicine that has the components name, disease of type string, dosage of type integer, and price of type float

Reviews

Write a Review

Computer Engineering Questions & Answers

  Mathematics in computing

Binary search tree, and postorder and preorder traversal Determine the shortest path in Graph

  Ict governance

ICT is defined as the term of Information and communication technologies, it is diverse set of technical tools and resources used by the government agencies to communicate and produce, circulate, store, and manage all information.

  Implementation of memory management

Assignment covers the following eight topics and explore the implementation of memory management, processes and threads.

  Realize business and organizational data storage

Realize business and organizational data storage and fast access times are much more important than they have ever been. Compare and contrast magnetic tapes, magnetic disks, optical discs

  What is the protocol overhead

What are the advantages of using a compiled language over an interpreted one? Under what circumstances would you select to use an interpreted language?

  Implementation of memory management

Paper describes about memory management. How memory is used in executing programs and its critical support for applications.

  Define open and closed loop control systems

Define open and closed loop cotrol systems.Explain difference between time varying and time invariant control system wth suitable example.

  Prepare a proposal to deploy windows server

Prepare a proposal to deploy Windows Server onto an existing network based on the provided scenario.

  Security policy document project

Analyze security requirements and develop a security policy

  Write a procedure that produces independent stack objects

Write a procedure (make-stack) that produces independent stack objects, using a message-passing style, e.g.

  Define a suitable functional unit

Define a suitable functional unit for a comparative study between two different types of paint.

  Calculate yield to maturity and bond prices

Calculate yield to maturity (YTM) and bond prices

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd