answersLogoWhite

0

#include<stdio.h>

#include<conio.h>

struct node

{

int data;

struct node *next;

};

typedef struct node NODE;

NODE* top = NULL;

void push()

{

NODE* temp;

int item;

temp = (NODE*)malloc (sizeof(NODE));

printf("Enter the item to be inserted-> ");

scanf("%d",&item);

temp->data = item;

temp->next = NULL;

if(top NULL)

{

printf("\n***Stack is empty***\n");

return;

}

else

{

temp = top;

printf("\nThe list is-> ");

while(temp != NULL)

{

printf("\t%d",temp->data);

temp = temp->next;

}

printf("\n");

}

}

int main()

{

int OP;

clrscr();

while(1)

{

printf("\n>>>CHOOSE OPTION<<<\n");

printf("\n 1.PUSH \n\n 2.POP \n\n 3.TRAVERSE \n\n 4.EXIT\n");

scanf("%d",&OP);

switch(OP)

{

case 1: push();

break;

case 2: pop();

break;

case 3: display();

break;

case 4: exit(1);

default:printf("\n\n\t<<WRONG OPTION PLEASE CHOOSE CORRECT OPTION>>\n\n");

break;

}

};

getch();

return 0;

}

User Avatar

Wiki User

13y ago

What else can I help you with?

Continue Learning about Engineering

What is the difference between implementation and algorithm?

An algorithm is a instruction for solving a problem. It is typically illustrated using prose, pseudo code or flowcharts, but other methods exist. The algorithm is the "here's how it's going to work" part of the solution. An implementation (of an algorithm) is a specific expression of this algorithm, using a specific programming language or any other suitable means. The implementation is the "here's how I've done it" part of the solution.


Can you provide a solution to the diamond-square algorithm using Java and recursion?

Yes. It is possible to provide a solution to the diamond-square algorithm using Java and recursion.


How do you implement stack without array?

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


An algorithm to Reversing the order of elements on stack S using 1 additional stacks?

// stack to contain content Stack sourceStack = new Stack(); // ... fill sourceStack with content // stack to contain reversed content Stack targetStack = new Stack(); while (!sourceStack.empty()) { targetStack.push(sourceStack.pop()); } // targetStack contains the reversed content of sourceStack


How do you overcome limitations of stacks in polygon filling?

You overcome limitations of the stack in polygon filling, or in any other algorithm, far that matter, but using an iterative technique, rather than a recursive technique. Recursion is quite useful, and can simplify algorithm design. Polygon filling, however, is a class of algorithm can potentially have a very deep recursion depth. This causes stress on the stack, hence the need for iteration.

Related Questions

What is the difference between implementation and algorithm?

An algorithm is a instruction for solving a problem. It is typically illustrated using prose, pseudo code or flowcharts, but other methods exist. The algorithm is the "here's how it's going to work" part of the solution. An implementation (of an algorithm) is a specific expression of this algorithm, using a specific programming language or any other suitable means. The implementation is the "here's how I've done it" part of the solution.


What is the runtime complexity of the Dijkstra algorithm?

The runtime complexity of the Dijkstra algorithm is O(V2) with a simple implementation using an adjacency matrix, or O(E V log V) with a more efficient implementation using a priority queue.


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

stack abstract datatype


What is the time complexity of the algorithm for finding the shortest path in a graph using Dijkstra's algorithm?

The time complexity of Dijkstra's algorithm for finding the shortest path in a graph is O(V2) with a simple implementation using an adjacency matrix, or O((V E) log V) with a more efficient implementation using a priority queue.


Can you provide a solution to the diamond-square algorithm using Java and recursion?

Yes. It is possible to provide a solution to the diamond-square algorithm using Java and recursion.


How do you implement stack without array?

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


An algorithm to Reversing the order of elements on stack S using 1 additional stacks?

// stack to contain content Stack sourceStack = new Stack(); // ... fill sourceStack with content // stack to contain reversed content Stack targetStack = new Stack(); while (!sourceStack.empty()) { targetStack.push(sourceStack.pop()); } // targetStack contains the reversed content of sourceStack


What is the runtime of Dijkstra's algorithm for finding the shortest path in a graph?

The runtime of Dijkstra's algorithm for finding the shortest path in a graph is O(V2) with a simple implementation using an adjacency matrix, or O((V E) log V) with a more efficient implementation using a priority queue.


What are Disadvantage of stack?

A stack is a LIFO (last-in, first-out) data structure such that only the top-most element is accessible and all new elements are pushed onto the top (analogous to a stack of plates). Stacks are advantageous when implementing a back-tracking algorithm but are ultimately useless for anything else. However, this is not a disadvantage. If you're not implementing a back-tracking algorithm then the problem is not the stack itself it is the fact that you are using the wrong type of container for your algorithm.


What is the running time of the Dijkstra algorithm for finding the shortest path in a graph?

The running time of the Dijkstra algorithm for finding the shortest path in a graph is O(V2) with a simple implementation using an adjacency matrix, or O((V E) log V) with a more efficient implementation using a priority queue.


What is the runtime complexity of Dijkstra's algorithm for finding the shortest path in a graph?

The runtime complexity of Dijkstra's algorithm for finding the shortest path in a graph is O(V2) with a simple implementation using an adjacency matrix, or O((V E) log V) with a more efficient implementation using a priority queue.


What is the time complexity analysis of Dijkstra's algorithm for finding the shortest path in a graph?

The time complexity of Dijkstra's algorithm for finding the shortest path in a graph is O(V2) with a simple implementation using an adjacency matrix, and O(E V log V) with a more efficient implementation using a priority queue.