Stacks: How to remain progress even the compiler is close

brianjay0914

Estimable
May 5, 2014
14
0
4,570
1
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")
}


 

brianjay0914

Estimable
May 5, 2014
14
0
4,570
1


hi . code blocks has a different COMPILER . its separate from the main codeblock application unlike turboc7 it compiles on the spot.

what i meant is . when u run the compiler the amount you push element there should not return to 0 when you close then compile it again . tried not puting return 0
 

brianjay0914

Estimable
May 5, 2014
14
0
4,570
1


sorry but dont know what you meant so heres the procedure
♥push 3 elements
♥traverse to see how many are pushed
♥close the compiler or just press 4 to quit
>>note that you didnt close the codeblocks application but just its compiler <<
♥run it again
♥traverse see if its still there. (basically what happen here is the inputed return to 0 and nothing can be seen )
 

brianjay0914

Estimable
May 5, 2014
14
0
4,570
1


I appreciate your effort . gratitude for that.
but how am I gonna do that . can you give me procedures
 

rgd1101

Polypheme
Moderator


What you teacher tell you how to do file i/o? If not maybe he/she want you to figure it out or read the book?
 

ASK THE COMMUNITY