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

  Majority of computer systems employ

Majority of computer systems employ fewer levels than what the OSI model specifies. This is true because of the way computer systems are constructed

  How one user segment would behave on a visit to the site

Using a website with which you are familiar, develop a scenario that tells the story of how one user segment would behave on a visit to the site.

  Derive the implication chart

For each of the following incompletely specified state tables, derive the implication chart; maximal compatibles.

  Create a web project using given information

The topic of your web pages will be about you and your journey through the course to this point. Get creative and add things about yourself, things you like.

  Write a test program that stores 5 million integers

Write a test program that stores 5 million integers in a linked list and test the time to traverse the list using an integer vs. using the get(index) methods.

  Describe cpdos and how to perform the exploit

Analyse potential threats to computer systems and networks and eval- uate countermeasures - Critically evaluate security policies and techniques

  Utilizing the dss-es-ess or intelligent systems

An American Company announced that it was interested in attaning a company in the health maintenance organization (HMO) field. Two decisions were included in this act: The decision to attain an HMO.

  If a class is derived protected from a base class describe

if a class is derived protected from a base class explain how this affects the inheritance of all the public protected

  Discuss when the use of cluster analysis is appropriate

Discuss when the use of Cluster Analysis is appropriate and why in data mining. Paper should be 6th edition and plagiarism free. The response nust be typed.

  How an interrupt handler would address the event

Set the context for the interrupt disk read and describe how an interrupt handler would address the event.

  How can you prevent your files from being overwritten

How can you prevent your files from being overwritten using the redirection symbols? How will you overwrite a file when needed?

  Prepare a schematic design of five-stage multiply pipeline

Prepare a schematic design of the five-stage multiply pipeline. All line widths and inter-stage connections must be shown.

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