This is my program of stacks. The problem is this that it does not show output. whenever I run the program, the output screen flashes and nothing else happens. (using Dev-C++)
Don't know what's the problem with it.
//****************************STACKS********************************
//===============Stacks using linked list(Arrays)=================
#include<iostream>
using namespace std;
int avail=-1, start=-1, i;
void ins();
void del();
void trav();
struct node
{
int data;
int link;
};
node arr[10];
int main()
{
int choice;
for (i=10; i>=0; i++)
{
arr[i].link=avail;
avail=i;
}
top:
cout<<"\n\tMain Menu";
cout<<"\n\t----------";
cout<<"\n1. Insertion";
cout<<"\n2. Deletion";
cout<<"\n3. Traversing";
cout<<"\n4. Exit";
cout<<"\n\nEnter your choice ";
cin>>choice;
switch(choice)
{
case 1:
ins();
break;
case 2:
del();
break;
case 3:
trav();
break;
case 4:
exit(0);
default:
cout<<"\nInvalid choice entered!";
system("PAUSE");
break;
}
goto top;
system("PAUSE");
return 0;
}
//=========================Insertion=========================
void ins()
{
int newnode;
int item;
cout<<"\nEnter any item to insert: ";
cin>>item;
if (avail==-1)
{
cout<<"\nOverflow";
return;
}
else
{
newnode=avail;
avail=arr[avail].link;
arr[newnode].data=item;
arr[newnode].link=start;
start=newnode;
}
}
//====================Deletion=====================
void del()
{
int loc;
if(start==-1)
{
cout<<"Underflow";
return;
}
else
{
loc=start;
start=arr[start].link;
arr[loc].link=avail;
avail=loc;
}
}
//===========================Traversing=========================================
void trav()
{
for (i=start; i!=-1; i=arr[i].link)
cout<<arr[i].data<<endl;
}