StackToSide

// stack_2t.cpp : Defines the entry point for the console application.

//

#include "stdafx.h"

#include

#include

using namespace std;

class myclass

{

public:

int a;

int *stack2;

int front;

int rear;

myclass(int x);

void add(int i,int item);

int del(int i);

};

myclass ::myclass(int x)

{

stack2=new int[x];

a=x;

front=0;

rear=a-1;

}

void myclass::add(int i,int item)

{

if(front==rear)

cout<<"\n"<<"@@@@@@@@@@ stack is full @@@@@@@@@"<<"\n";

else

{

if(i==0)

{

stack2[++front]=item;

}

if(i==1)

{

stack2[--rear]=item;

}

}

}

int myclass::del(int i)

{

if(front==0 && rear==a-1)

{

cout<<" @@@@@@ stack is empty @@@@@@";

}

else

{

if(i==0)

{

return stack2[--front];

}

if(i==1)

{

return stack2[++rear];

}

}

}

int _tmain(int argc, _TCHAR* argv[])

{

int c;

int c1;

int item;

cout<<"Enter the size of stack : ";

cin>>c;

myclass s1(c);

for(int i=0;i

{

cout<<"Enter number of stack : ";

cin>>c1;

cout<<"Enter one number : ";

cin>>item;

s1.add(c1,item);

}

for(int i=0;i

{

cout<<"Enter number of stack :";

cin>>c1;

cout<<"\n"<"\n";

}

getch();

return 0;

}
Example:
input:1 2 3 4 5 6 7 8 9
result in memory [1][3][5][7][9][8][6][4][2]

Description

if you Enter Some numbers in the Stack one number has inserted in Left Side and another one has inserted in Right Side.

Details

Double click on the code to select all.

 

;