BEFORE ANYTHING ELSE THIS IS THE MAIN CODE
SO WHAT IM POINTING AT .
IF I PUSH EXAMPLE 3 ELEMENTS THEN I POP 1 THEN I CLOSE MY COMPILER.
MY TEACHER WANTS ME TO NOT LOSE THE PROGRESS.
AND WHEN SHE COMPILE IT AGAIN SHES GONNA SEE THE 2 LEFT ,
NOT START FROM THE 0.
CODEBLOCKS
I HOPE YOU GOT MY POINT. IGNORE MAX
THANKS
#include <iostream>
#include <conio.h>
using namespace std;
int choice,MAX,yasna,element,dispNode;
struct Node
{
int data;
Node *link;
};
Node *top;
int ctr;
void setListStack()
{
top=NULL;
ctr=0;
}
void push(int element)
{
cout<<"Enter a Number to your Element: ";
cin>>element;
Node*temp=new Node();
temp->data=element;
temp->link=top;
top=temp;
ctr++;
}
int pop()
{
int ret;
if (top==NULL)
{
cout<<"Hey Stacks are currently EMPTY!\n"<<"Hint: Try pushing some by clicking [1] in MENU"<<endl;
}
else
{
ret=top->data;
Node*temp=top->link;
delete top;
top =temp;
ctr--;
return ret;
}
}
int traverse()
{
Node *dispNode;
dispNode = top;
if (top == NULL)
cout<<"Stack is currently empty until you push element. \n To do that try pressing [1] at the menu"<<endl;
else
{
cout<<"Stack elements :"<<endl;
while (dispNode != NULL)
{
cout<<dispNode->data<<endl;
dispNode = dispNode->link;
}
}
}
int menu()
{
cout<<"===================================="<<endl;
cout<<"[1]Push element into the Stack"<<endl<<"[2]Pop Element from the Stack"<<endl<<"[3]Traverse the Stack"<<endl<<"[4]QUIT"<<endl;
cout<<"===================================="<<endl;
cout<<"Enter your Choice !:";
cin>>choice;
cout<<"===================================="<<endl;
switch(choice)
{
case 1:
{
push(element);
menu();
break;
}
case 2:
{
cout<<"Pop Element-> "<<pop()<<endl;
menu();
break;
}
case 3:
{
traverse();
menu();
break;
}
case 4:
{
cout<<"Are you sure you want to quit? \n [1]YASS , [2]NAHH ->: ";
cin>>yasna;
if (yasna==1)
{
cout<<endl<<" <<<<<<<<<<<<<<<<oOo>>>>>>>>>>>>>>>>>"<<endl;
cout<<" Ok then have a good day!"<<endl;
cout<<" <<<<<<<<<<<<<<<<oOo>>>>>>>>>>>>>>>>>\n"<<endl;
}
if (yasna==2)
{
cout<<endl<<"<<<<<<<<<<<<<<<<oOo>>>>>>>>>>>>>>>>>"<<endl;
cout<<" Yass Sirrrr!"<<endl;
cout<<"<<<<<<<<<<<<<<<<oOo>>>>>>>>>>>>>>>>>\n"<<endl;
menu();
}
break;
}
default:
{
cout<<endl<<"INVALID\n"<<endl;
menu();
}
}
}
int main()
{
menu();
//System("pause")
}
SO WHAT IM POINTING AT .
IF I PUSH EXAMPLE 3 ELEMENTS THEN I POP 1 THEN I CLOSE MY COMPILER.
MY TEACHER WANTS ME TO NOT LOSE THE PROGRESS.
AND WHEN SHE COMPILE IT AGAIN SHES GONNA SEE THE 2 LEFT ,
NOT START FROM THE 0.
CODEBLOCKS
I HOPE YOU GOT MY POINT. IGNORE MAX
THANKS
#include <iostream>
#include <conio.h>
using namespace std;
int choice,MAX,yasna,element,dispNode;
struct Node
{
int data;
Node *link;
};
Node *top;
int ctr;
void setListStack()
{
top=NULL;
ctr=0;
}
void push(int element)
{
cout<<"Enter a Number to your Element: ";
cin>>element;
Node*temp=new Node();
temp->data=element;
temp->link=top;
top=temp;
ctr++;
}
int pop()
{
int ret;
if (top==NULL)
{
cout<<"Hey Stacks are currently EMPTY!\n"<<"Hint: Try pushing some by clicking [1] in MENU"<<endl;
}
else
{
ret=top->data;
Node*temp=top->link;
delete top;
top =temp;
ctr--;
return ret;
}
}
int traverse()
{
Node *dispNode;
dispNode = top;
if (top == NULL)
cout<<"Stack is currently empty until you push element. \n To do that try pressing [1] at the menu"<<endl;
else
{
cout<<"Stack elements :"<<endl;
while (dispNode != NULL)
{
cout<<dispNode->data<<endl;
dispNode = dispNode->link;
}
}
}
int menu()
{
cout<<"===================================="<<endl;
cout<<"[1]Push element into the Stack"<<endl<<"[2]Pop Element from the Stack"<<endl<<"[3]Traverse the Stack"<<endl<<"[4]QUIT"<<endl;
cout<<"===================================="<<endl;
cout<<"Enter your Choice !:";
cin>>choice;
cout<<"===================================="<<endl;
switch(choice)
{
case 1:
{
push(element);
menu();
break;
}
case 2:
{
cout<<"Pop Element-> "<<pop()<<endl;
menu();
break;
}
case 3:
{
traverse();
menu();
break;
}
case 4:
{
cout<<"Are you sure you want to quit? \n [1]YASS , [2]NAHH ->: ";
cin>>yasna;
if (yasna==1)
{
cout<<endl<<" <<<<<<<<<<<<<<<<oOo>>>>>>>>>>>>>>>>>"<<endl;
cout<<" Ok then have a good day!"<<endl;
cout<<" <<<<<<<<<<<<<<<<oOo>>>>>>>>>>>>>>>>>\n"<<endl;
}
if (yasna==2)
{
cout<<endl<<"<<<<<<<<<<<<<<<<oOo>>>>>>>>>>>>>>>>>"<<endl;
cout<<" Yass Sirrrr!"<<endl;
cout<<"<<<<<<<<<<<<<<<<oOo>>>>>>>>>>>>>>>>>\n"<<endl;
menu();
}
break;
}
default:
{
cout<<endl<<"INVALID\n"<<endl;
menu();
}
}
}
int main()
{
menu();
//System("pause")
}