#include<iostream.h>
#include<conio.h>
#define size 5
int stack[size],top=-1;
void push(int s[size],int &t,int m);
int pop (int s[size],int &t);
void main()
{
clrscr();
cout<<"1-push \n 2-pop \n 3-exit \n";
int x,y;
do
{
cout<<"enter number to choice:";
cin>>x;
switch(x)
{
case 1:
cout << "enter anumber to push in stack \n";
cin >> y;
push(stack, top, y)
break;
case 2:
y = pop(stack, top);
if(y == -1)
cout << "\n empty \n";
else
cout << "\n popis ok \n y=" << y << "\n";
break;
}
} while( x != 3 );
getch();
}
void push(int s[size], int &t, int m)
{
if(t == size-1)
cout << "the stack is full \n";
else
s[++t] = m;
}
int pop(int s[size], int &t)
{
if(t==-1)
return -1;
else
return s[t--];
}
abbashadwan 0 Newbie Poster
Recommended Answers
Jump to Post
void main()
That's not C++.
Jump to PostDo you have a question?
As for the code, there are several problems with it:
- The header
#include <iostream.h>
has been deprecated for a long time, it is a pre-standard syntax that some compilers still support today, but it is not standard. The standard libraries do not have a ".h" …
Jump to PostC++ has supported an implicit return from main() since C++98, and C has supported it since C99.
Yes, I was just testing you to see if you knew it too :) Guess I'm getting obsolete.
All 12 Replies
Moschops 683 Practically a Master Poster Featured Poster
mike_2000_17 2,669 21st Century Viking Team Colleague Featured Poster
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster
mike_2000_17 2,669 21st Century Viking Team Colleague Featured Poster
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster
NathanOliver 429 Veteran Poster Featured Poster
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster
NathanOliver 429 Veteran Poster Featured Poster
Tumlee 42 Junior Poster in Training
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster
deceptikon 1,790 Code Sniper Team Colleague Featured Poster
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster
deceptikon commented: ;) +12
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.