queues
queues
queues
void insert()
{
int num;
if(rear==max-1){
printf("\nQueue is Full !\n");
return;
}
printf("\nEnter a number for insert :");
scanf("%d",&num);
if(front==-1)
front=front+1;
rear=rear+1;
queue[rear]=num;
}
int delete()
{
int num;
if(front==-1 || front==rear+1)
{
printf("\nQueue is Empty !\n");
return 0;
}
num=queue[front];
printf("\n%d was deleted !\n",num);
front=front+1;
}
void display()
{
int i;
if(front==-1 || front==rear+1)
{
printf("\nQueue Is Empty ! Nothing To Display !!");
return;
}
printf("\n\n");
for(i=front;i<=rear;i++)
printf("%d\t",queue[i]);
printf("\n");
}
Out put:::
1. Insert
2. Delete
3. Display
4. EXIT
Enter What you want :1
1. Insert
2. Delete
3. Display
4. EXIT
Enter What you want :3
4 8 9
1. Insert
2. Delete
3. Display
4. EXIT
Enter What you want :
#include<stdio.h>
#include<ctype.h>
char stack[100];
int top = -1;
void push(char x)
{
stack[++top] = x;
}
char pop()
{
if(top == -1)
return -1;
else
return stack[top--];
}
int priority(char x)
{
if(x == '(')
return 0;
if(x == '+' || x == '-')
return 1;
if(x == '*' || x == '/')
return 2;
return 0;
}
int main()
{
char exp[100];
char *e, x;
printf("Enter the INFIX expression : ");
scanf("%s",exp);
printf("\n");
e = exp;
while(*e != '\0')
{
if(isalnum(*e))
printf("%c ",*e);
else if(*e == '(')
push(*e);
else if(*e == ')')
{
while((x = pop()) != '(')
printf("%c ", x);
}
else
{
while(priority(stack[top]) >= priority(*e))
printf("%c ",pop());
push(*e);
}
e++;
}
while(top != -1)
{
printf("%c ",pop());
}return 0;
}
OUT PUT:
abc*+
int main() {
char string1[20];
int i, length;
int flag = 0;
printf("Enter a string: ");
scanf("%s", string1);
length = strlen(string1);
for (i = 0; i < length / 2; i++) {
if (string1[i] != string1[length - i - 1]) {
flag = 1;
break;
}
}
if (flag) {
printf("%s is not a palindrome\n", string1);
} else {
printf("%s is a palindrome\n", string1);
}
return 0;
}
OUT PUT:
Enter a string: AROME
AROME is not a palindrome
iii) Implement a stack or queue to perform comparison and check for symmetry