Stack using single link list in c++

 Stack using single link list in c++

#include<iostream>
using namespace std;
class Pile{
public:
int plate;
Pile *next;
Pile *top = NULL;
void push(int val)
{
Pile *temp = new Pile;
temp->plate = val;
temp->next = top;
top = temp;
}
int pop()
{
if (isEmpty())
{
cout << "There is no plate" << endl;
return 0;
}
else
{
Pile *temp = top;
top = top->next;
delete(temp);
return top->plate;
}
}
bool isEmpty()
{
return (top == NULL);
}
int peek()
{
if (isEmpty())
{
cout << "There is no plate" << endl;
return 0;
}
else
{
return top->plate;
}
}

};
int main()
{
Pile blue;
blue.push(5);
blue.push(55);
blue.push(11);
blue.pop();
blue.pop();
cout << "Value is:" << blue.peek() << endl;
getchar();
getchar();
return 0;
}

Comments

Popular posts from this blog

Multiple inheritance,friend function and multiple file in oop(object oriented programming)

Concepts of OOP (object oriented programming)

Concepts in c++........