New Member FAQ | Forums | Earn Revenue


Resources Entrance Ask Experts Exam Papers Jobs English Projects Universities Colleges Courses Schools Training My India



My Profile
Active Members
TodayLast 7 Days more...



Awards & Gifts
Online Exams

Fresher Jobs


Our fresher job section is exclusively for fresh graduates! Find jobs for freshers in major Indian cities including Bangalore, Chennai, Hyderabad, Pune or Kochi

Resources


Find educational articles, blogs, discussion threads and other resources.

Colleges


Find details about any college in India or search for courses.

website counter



STACK


Posted Date:     Total Responses: 0    Posted By: PRITESH   Member Level: Bronze   Points/Cash: 4   


// PRAJAPATI PRITESH
#include
#include
#include
int top=-1;
int s[10];
int n;
void push(int);
int pop(void);
int peep(int);
int change(int,int);
void display(int []);

void main()
{
int ch,i,index,x,y,z;
char c;
clrscr();
printf("\n Enter the size of the stack ");
scanf("%d",&n);
do
{
printf(" Enter \n 1.Push\n 2.Pop\n 3.Peep\n 4.Change\n 5.Display \n ");
scanf("%d",&ch);
switch(ch)
{
case 1:
printf("\n Enter the element ");
scanf("%d",&x);
push(x);
display(s);
break;

case 2:
y=pop();
if(y!=-1)
printf("\n %d has been selected\n ",y);
display(s);
break;

case 3:
printf("\n Enter the index no.");
scanf("%d",&index);
z=peep(index);
if(z!=-1)
printf("\n %d is the value at %d\n",z,index);
display(s);
break;

case 4:
scanf("%d",&i);
scanf("%d",&x);
change(i,x);
display(s);
break;

case 5:
display(s);
break;

default :
printf("\t \n Invalid Input");
break;
}
printf("\n \n Want to cont???");
flushall();
scanf("%c",&c);
}
while(c=='y');
getch();
}

// 4 PUSH
void push(int x)
{
if(top==n-1)
{
printf(" Stack Over Flow ");
}
else
{
top=top+1;
s[top]=x;
}
}


// 4 DISPLAY
void display(int s[10])
{
int i;
if(top==-1)
printf(" Empty STACK");
else
{
for(i=top;i>=0;i--)
{
printf("%d ",s[i]);
}
}
}


// 4 POP
int pop(void)
{
if(top==-1)
{
printf("Stck Underflow");
return(-1);
}
else
{
top=top-1;
return(s[top+1]);
}
}

// 4 PEEP
int peep(int i)
{
if((top-i+1)<=0)
{
printf("\nStack Underflow");
return(-1);
}
else
{
return(s[top-i+1]);
}
}

// 4 CHANGE
int change(int i,int x)
{
if((top-i+1)<=0)
return(-1);
else
{
s[top-i+1]=x;
return(s[top-i+1]);
}
}


Project Feedbacks

Author: v.danesh kumarMember Level: SilverRevenue Score: 1 out of 5
this a college lab program or computer project .but according to me this one likes to me lab program


Author: SuganyaMember Level: SilverRevenue Score: 1 out of 5
Hi,
this program works well. It will be even more good if the output is formatted.


Post Feedback
You must Sign In to post a feedback.
Next Project: KNAPSACK PROBLEM
Previous Project: A Real Dictionary using TRIES Data Structure

Return to Project Index

Post New Project


Related Projects



Advertise Here





Contact Us   Advertise   Editors    Privacy Policy    Terms Of Use   

ISC Technologies.
2006 - 2009 All Rights Reserved.