Beruflich Dokumente
Kultur Dokumente
/* Declaration of functions */
//Function to display the menu
void menu();
//Function to initialise the double stack
void initdbstk(dblstk *);
//Function to add an element in the first stack
int pushBeg(dblstk *,int );
//Function to add an element in the second stack
int pushEnd(dblstk *,int );
//Function to serve an element from the first stack
int popBeg(dblstk *,int *);
//Function to serve an element from the second stack
int popEnd(dblstk *,int *);
//Function to check if the double stack is empty
int IsEmpty(dblstk );
//Function to check if the first stack is empty
int IsEmptyStk1(dblstk );
//Function to check if the second stack is empty
int IsEmptyStk2(dblstk );
//Function to check if the double stack is full
int IsFull(dblstk );
//Function to check if the first stack is full
int IsFullStk1(dblstk );
//Function to check if the second stack is full
int IsFullStk2(dblstk );
//Function to display the double stack elements
void display (dblstk );
//MAIN FUNCTION
void main()
{
clrscr();//clears the user screen
menu(); //Function call
getch();
}
void menu()
{
dblstk dst;
int info,choice,call,flag;
call=flag=0;
initdbstk(&dst);//FUNCTION CALL
while(1)
{
clrscr();
printf("********MENU********\n");
printf("1. Push in first stack!\n");
printf("2. Push in second stack!\n");
printf("3. Pop from first stack!\n");
printf("4. Pop from second stack!\n");
printf("5. To check if the stack is empty!\n");
printf("6. To check if the stack is full!\n");
printf("7. Display!\n");
printf("8. Exit!\n");
printf("Your choice: ");
scanf("%i",&choice);
switch(choice)
{
case 1:printf("Enter the element to be pushed in first stack: ");
scanf("%i",&info);
call=pushBeg(&dst,info); //Function call[Push in first stack]
if(call)
printf("Element is pushed!");
else
printf("Element can't be pushed!");
getch();
break;
//Displaying stack 2
printf("\n\nSTACK 2:\n");
if(IsEmptyStk2(dblst))
printf("This stack is empty!");
else
{
for(i=dblst.top[1];i<MAX;i++)
printf("%i\t",dblst.Arr[i]);
}
}
/*
OUTPUT
********MENU********
1. Push in first stack!
2. Push in second stack!
3. Pop from first stack!
4. Pop from second stack!
5. To check if the stack is empty!
6. To check if the stack is full!
7. Display!
8. Exit!
Your choice: 1
Enter the element to be pushed in first stack: 1
Your choice: 1
Enter the element to be pushed in first stack: 2
Your choice: 1
Enter the element to be pushed in first stack: 3
Your choice: 2
Enter the element to be pushed in second stack: 4
Your choice: 7
STACK 1:
1 2 3
STACK 2:
4
*/