Professional Documents
Culture Documents
//Question-1
#include<stdio.h>
#define MAX 106
int qA[MAX]; //implementing queue using array
int rear1=-1,front1=-1;
int main()
{
int i,n,temp,qB[MAX],front2,rear2;
printf("Enter the size of list: ");
scanf("%d",&n);
printf("Enter the elements of list:\n");
for(i=0;i<n;i++)
{
scanf("%d",&temp);
insert(temp);
}
temp=n-1;
//loop for checking conditions given in question and printing the output
while(front1<=rear1 && front2<=rear2)
{
if(qA[front1]>qB[front2])
{
printf("1 ");
front2++;
}
else if(qA[front1]<qB[front2])
{
printf("2 ");
front1++;
}
else
{
printf("0 ");
front1++;
front2++;
}
}
return 0;
}
//Question-2
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#define MAX 1000
struct stack
{
char stk[MAX];
int top;
}s; //creating stack
int main()
{
char str[MAX],a[MAX][4];
int i=0,j=0,n;
s.top=-1;
printf("Enter number of strings: ");
scanf("%d",&n);
printf("Enter strings:\n");
for(j=0;j<n;j++)
{
scanf("%s",str);
for(i=0;i<strlen(str);i++)
{
if(str[i]=='(' || str[i]=='[' || str[i]=='{')
{
push(str[i]);
continue;
}
else if(str[i]==')' || str[i]==']' || str[i]=='}')
{
if(str[i]==')')
{
if(s.stk[s.top]=='(')
pop();
else
{
strcpy(a[j],"NO");
break;
}
}
if(str[i]==']')
{
if(s.stk[s.top]=='[')
pop();
else
{
strcpy(a[j],"NO");
break;
}
}
if(str[i]=='}')
{
if(s.stk[s.top]=='{')
pop();
else
{
strcpy(a[j],"NO");
break;
}
}
}
}
if(s.top==-1)
strcpy(a[j],"YES");
s.top=-1;
}
for(i=0;i<n;i++)
{
for(j=0;a[i][j]!='\0';j++)
printf("%c",a[i][j]);
printf("\n");
}
return 0;
}
Output
Question-1
Question-2