MCPcopy Create free account
hub / github.com/Lakhankumawat/LearnCPP / main

Function main

S-Stack/stackADTUsingLL.cpp:101–142  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

99}
100
101int main(){
102 int* dataPtr;
103
104 STACK* stack;
105
106 stack = createStack();
107
108 //For the sake of simplicity the program uses the integer data in the stack.
109 //However the above funtions can be used for any data types
110
111 int ch, n;
112 while(true){
113 cout << "1.Push an item 2.Pop an item 3.Retrieve stack top 4.Check empty 5.Stack count 6.Display 7.EXIT\n";
114 cout << "Enter your choice : ";
115 cin >> ch;
116 switch(ch){
117 case 1: cout << "Enter an item : ";
118 cin >> n;
119 dataPtr = (int*)malloc(sizeof(int));
120 *dataPtr = n;
121 pushStack(stack, dataPtr);
122 break;
123 case 2: dataPtr = (int*) popStack(stack);
124 printf("Popped data is : %d\n", *dataPtr);
125 break;
126 case 3: dataPtr = (int*) stackTop(stack);
127 printf("The stack top is : %d\n", *dataPtr);
128 break;
129 case 4: if(!emptyStack(stack))
130 cout << "Stack is not empty" << endl;
131 else
132 cout << "Stack is empty" << endl;
133 break;
134 case 5: cout << "The no.of elements is " << stackCount(stack) << endl;
135 break;
136 case 6: display(stack);
137 break;
138 case 7: exit(0);
139 }
140 }
141 return 0;
142}

Callers

nothing calls this directly

Calls 7

createStackFunction · 0.85
pushStackFunction · 0.85
popStackFunction · 0.85
stackTopFunction · 0.85
emptyStackFunction · 0.85
stackCountFunction · 0.85
displayFunction · 0.70

Tested by

no test coverage detected