answersLogoWhite

0

struct node

{

int info;

struct node *link;

} *top=NULL;

int main()

{

int choice;

while(1)

{ printf("1.Push\n");

printf("2.Pop\n");

printf("3.Display\n");

printf("4.Quit\n");

printf("Enter your choice : ") ;

scanf("%d", &choice);

switch(choice)

{

case 1:

push();

break;

case 2:

pop();

break;

case 3:

display();

break;

case 4:

exit(1);

default :

printf("Wrong choice\n");

}/*End of switch */

}/*End of while */

return 0;

}/*End of main() */

void push()

{

struct node *tmp;

int pushed_item;

tmp = malloc(sizeof(struct node));

printf("Input the new value to be pushed on the stack : ");

scanf("%d",&pushed_item);

tmp->info=pushed_item;

tmp->link=top;

top=tmp;

}/*End of push()*/

void pop()

{

struct node *tmp;

if(top == NULL)

printf("Stack is empty\n");

else

{ tmp=top;

printf("Popped item is %d\n",tmp->info);

top=top->link;

free(tmp);

}

}/*End of pop()*/

void display()

{ struct node *ptr;

ptr=top;

if(top==NULL)

printf("Stack is empty\n");

else

{

printf("Stack elements :\n");

while(ptr!= NULL)

{

printf("%d\n",ptr->info);

ptr = ptr->link;

}/*End of while */

}/*End of else*/

}/*End of display()*/

User Avatar

Wiki User

15y ago

What else can I help you with?

Related Questions

Is it possible to implement stack and queues using linkes list?

Yes it is possible to implement stack and queue using linked list


How do you implement a doubly linked list by using singly linked list?

Add another pointer to the nodes for the previous node: struct node { struct node *next; struct node *previous; void *data; }; typedef struct node node; Then change the logic for insertion and removal to make sure you set the previous pointer as well as the next one.


How do you implement stack without array?

Stacks are often implemented using the same node structure as a linked list.


Explain The merits of using a deque to implement a stack in data structure?

Explain The merits of using a deque to implement a stack in data structure


What is the C plus plus programs to implement the stack ADT using a singly linked list?

#include<iostream> #include<time.h> #include<forward_list> int main() { // seed random number generator srand ((unsigned) time(NULL)); // a forward_list is a singly-linked list std::forward_list<int> stack; // push 10 integers onto stack for (int loop=0; loop<10; ++loop) { int num=rand(); std::cout<<"Pushing "<<num<<std::endl; stack.push_front (num); } // pop all integers while (!stack.empty()) { std::cout<<"Popping "<<stack.front()<<std::endl; stack.pop_front(); } }


What are advantages of stack?

some disadvantages created in stack using array then that problem solve to linked list use in stack.First advantage for size of stack not limited in linked list using.second essay to stack programme implement using only one pointer.


Which of the following data structures can be randomly accessed giving loc A. linked list implemented using array B. singly linked list C. double linked list D. both single and double linked list?

Which of the following data structures can be randomly accessed giving loc?A. linked list implemented using arrayB. singly linked listC. double linked listD. both single and double linked listThe answer is A.


Can you implement merge sort without using recursion?

Sure, recursion can always be substituted with using a stack.


How can you implement a queue using stacks efficiently?

To implement a queue using stacks efficiently, you can use two stacks. One stack is used for enqueueing elements, and the other stack is used for dequeueing elements. When dequeueing, if the dequeue stack is empty, you can transfer elements from the enqueue stack to the dequeue stack to maintain the order of elements. This approach allows for efficient implementation of a queue using stacks.


C program to implement tower of hanoi using array implementation of stack abstract datatype?

stack abstract datatype


Evaluate the polynomial expression using linked list using c?

Evaluating a Polynomial expression using a singly linked list visit : http://myfundatimemachine.blogspot.in/2012/06/polynomial-evaluation-in-c.html


What is the relationship between a stack and an array?

There is no inherent relationship between the two. It's possible to implement a stack using an array to store date, but that's about it.