Menu C++
Menu C++
![]() |
| Add caption |
#include<bits/stdc++.h>
using namespace std;
void insertFunction();
void deleteFunction();
void displayFunction();
void exitFunction();
int stackArray[100];
int topIndex = -1, item =0;
int main()
{
while(1)
{
system("cls");
printf("Enter your choice: \n1. Insert/Push\n2. Delete/POP\n3. Display\n4. Exit\n\n");
int a;
scanf("%d",&a);
switch(a)
{
case 1:
insertFunction();
break;
case 2:
deleteFunction();
break;
case 3:
displayFunction();
break;
case 4:
exitFunction();
break;
default:
printf("Wrong input\n");
system("pause");
}
}
return 0;
}
void insertFunction()
{
system("cls");
printf("Insert your value:\n");
scanf("%d", &item);
if (topIndex < 100){
topIndex++;
stackArray[topIndex] = item;
}
else
printf("Overflow");
printf("Inserted\n\n");
system("pause");
}
void deleteFunction()
{
system("cls");
if( topIndex == 0)
printf("Your stack is Empty");
else
topIndex--;
printf("Deleted\n\n");
system("pause");
}
void displayFunction()
{
system("cls");
printf("Your Stack:\n");
for ( int i = topIndex; i >= 0 ; i--)
printf("%d ", stackArray[i]);
puts("");
system("pause");
}
void exitFunction()
{
printf("Exiting...");
exit(0);
}

Comments
Post a Comment