Solution:
#include<stdio.h>
#include<conio.h>
#define maxsize 50
struct stack
{
int stk[maxsize];
int top;
};
typedef struct stack STACK;
STACK s1,s2;
int i,n;
int mid;
void array();
void push1();
void push2();
void traverse1();
void traverse2();
void main()
{
s1.top=-1;
s2.top=-1;
clrscr();
array();
push1();
push2();
traverse1();
traverse2();
}
void array()
{
int arr[50];
printf("\n enter the no of array ele to be stored ::");
scanf("%d",&n);
mid=n/2;
printf("\n enter the array elements ::\n");
for(i=0;i<n;i++)
{
printf("\n enter arr[%d] ::\t",i);
scanf("%d",&arr[i]);
}
}
void push1()
{
int arr[50];
if(s1.top== (maxsize-1))
{
printf("\n stack is full ");
}
else
{
for(i=0;i<mid;i++)
{
s1.top=s1.top+1;
s1.stk[s1.top]=arr[i];
}
}
}
void push2()
{ int arr[50];
if(s2.top== (maxsize-1))
{
printf("\n stack is full ");
}
else
{
for(i=mid;i<n;i++)
{
s2.top=s2.top+1;
s2.stk[s2.top] =arr[i];
}
}
}
void traverse1()
{
int i;
if(s1.top==-1)
{
printf("\n nothing to display , stack is empty ::");
}
else
{
printf("\n");
printf("\n stack 1 :");
for(i=s1.top;i>=0;i--)
{
printf("\n %d",s1.stk[i]);
}
}
}
void traverse2()
{
if(s2.top==-1)
{
printf("\n nothing to display , stack is empty ::");
}
else
{
printf("\n");
printf("\n stack 2 :");
for(i=s2.top;i>=0;i--)
{
printf("\n %d",s2.stk[i]);
}
}
}
#include<stdio.h>
#include<conio.h>
#define maxsize 50
struct stack
{
int stk[maxsize];
int top;
};
typedef struct stack STACK;
STACK s1,s2;
int i,n;
int mid;
void array();
void push1();
void push2();
void traverse1();
void traverse2();
void main()
{
s1.top=-1;
s2.top=-1;
clrscr();
array();
push1();
push2();
traverse1();
traverse2();
}
void array()
{
int arr[50];
printf("\n enter the no of array ele to be stored ::");
scanf("%d",&n);
mid=n/2;
printf("\n enter the array elements ::\n");
for(i=0;i<n;i++)
{
printf("\n enter arr[%d] ::\t",i);
scanf("%d",&arr[i]);
}
}
void push1()
{
int arr[50];
if(s1.top== (maxsize-1))
{
printf("\n stack is full ");
}
else
{
for(i=0;i<mid;i++)
{
s1.top=s1.top+1;
s1.stk[s1.top]=arr[i];
}
}
}
void push2()
{ int arr[50];
if(s2.top== (maxsize-1))
{
printf("\n stack is full ");
}
else
{
for(i=mid;i<n;i++)
{
s2.top=s2.top+1;
s2.stk[s2.top] =arr[i];
}
}
}
void traverse1()
{
int i;
if(s1.top==-1)
{
printf("\n nothing to display , stack is empty ::");
}
else
{
printf("\n");
printf("\n stack 1 :");
for(i=s1.top;i>=0;i--)
{
printf("\n %d",s1.stk[i]);
}
}
}
void traverse2()
{
if(s2.top==-1)
{
printf("\n nothing to display , stack is empty ::");
}
else
{
printf("\n");
printf("\n stack 2 :");
for(i=s2.top;i>=0;i--)
{
printf("\n %d",s2.stk[i]);
}
}
}
Comments
Post a Comment
Thank you