Shopping In MUMBAI

Are you searching for Discounts, offers, sale in Mumbai ? You are in the right place. MUMBAI, a shopping haven, has no dearth of great discounts and sales. This blog features the best MUMBAI shopping offers, sale, discounts and deals and bargains CURRENTLY GOING on in Mumbai plus a few free things thrown in on top. Don't wait for it because once they are gone, they are gone. Hurry!..By clicking the "Like" button you will receive a daily update of discounts, sale, offers going on in Mumbai. LIKE IT.... SHARE IT...njoY.

Sunday, May 31, 2009

Data structure Program to Implement operations on stacks.

Implement Push, Pop, Peek and Display operations on stacks maintained using arrays or linked list.


/* Stack Operations - arrays */

#include
#include
#define SIZE 10

int stack[SIZE], top = 0;
void push(void);
void pop(void);
void display(void);

void main()
{
int choice = 1;
while (choice == 1 || choice == 2 || choice == 3)
{
clrscr();
printf("Stack Implementation Using Arrays :-\n");
printf("----- -------------- ----- ------\n\n");
printf("1] Push an element onto the stack\n");
printf("2] Pop an element from the stack\n");
printf("3] Display the stack elements\n");
printf("4] Exit\n\n");
printf("Enter your choice :- ");
scanf("%d",&choice);
switch (choice)
{
case 1 :
push();
break;
case 2 :
pop();
break;
case 3 :
display();
break;
case 4 :
break;
default :
printf("\nOut of range\n\n");
choice = 1;
getch();
}
}
clrscr();
printf("\nProgram finished......");
getch();
}

/* Function to push an element onto the stack */
void push(void)
{
int value;
if (top == SIZE)
{
printf("\nStack Full...cannot push...");
getch();
}
else
{
printf("\nEnter the element value : ");
scanf("%d", &value);
stack[top] = value;
top++;
}
return;
}

/* Function to pop an element from the stack */
void pop(void)
{
int value;
if (top == 0)
{
printf("\nStack Empty...can not pop...");
getch();
}
else
{
value = stack[top-1];
printf("\n%d is popped from the stack...", value);
getch();
top--;
}
return;
}

/* Function to display all the elements of the stack */
void display(void)
{
int i;
if (top == 0)
{
printf("\nStack empty...No elements to display...");
getch();
}
else
{
printf("\nStack elements are :-\n\n");
for (i=0; i<=(top-1); i++)
{
printf("%d ----> %d\n", (i+1), stack[i]);
}
getch();
}
return;
}


OUTPUT:-

Stack Implementation Using Arrays :-
----- -------------- ----- ------
1] Push an element onto the stack
2] Pop an element from the stack
3] Display the stack elements
4] Exit

Enter your choice :- 3

Stack elements are :-

1 ----> 11
2 ----> 22
3 ----> 33
4 ----> 44


Enter your choice :- 4

Data structure Program to Implement operations on stacks.SocialTwist Tell-a-Friend

0 comments:

SUPPORT THIS BLOG