ASSIGN. 3 CS-392-TCPTUTOR

10
132

Algorithm for linear queue

front->pointer from which dat will be deleted
rear->pointe rfrom which dat will be entered
queue[]->array which hold the element in the queue
max->maximum size of the array
value->value to be entered in the queue

3

Algorithm for insetrintion operation (enqueue)
Step 1: if rear=max-1
print “overflow”
goto step4
[End of if block]
Step 2: if front=-1 and rear=-1
Set front=0,rear=0
else
set rear=rear+1
step 3: set queue[rear]=value
step 4: Exit

Algorithm for deletion operation(delqueue)
Step 1: if front=-1 or front>rear
print “underflow”
goto step2
else
Set val=queue[front]
Set front=front+1
step 2: Exit

Algorithm for display all elements in queue
step 1: [initilize] i=front
step 2: repeat step 3 and 4, while i<=rear
step 3: print queue[i]
step 4: set i=i+1
step 5: Exit

SOURCE CODE

#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
#define max 10
int queue[max];
int front=-1,rear=-1;
void enqueue(int value)
{
if(rear==max-1)
printf(“End of queue”);
else
{
if(front==-1&&rear==-1)
{
front=0;
rear=0;
}
else
{
rear=rear+1;
}
queue[rear]=value;
}
}
void delqueue()
{
if(front==-1||front>rear)
printf(“queue underflow”);
else
{
printf(“Deleted value is:%d”,queue[front]);
front=front+1;
}
}
void display()
{
int i;
printf(“Values are:”);
for(i=front;i<=rear;i++)
{
printf(“%d,”,queue[i]);
}
}
void main()
{
int choice,value;
while(1)
{
printf(“\n1. Insert”);
printf(“\n2. Delete”);
printf(“\n3. Display”);
printf(“\n4. Exit”);
printf(“Enter your choice:”);
scanf(“%d”,&choice);
switch(choice)
{
case 1:
printf(“Enter the value in queue:”);
scanf(“%d”,&value);
enqueue(value);
break;
case 2:
delqueue();
break;
case 3:
display();
break;
case 4:
exit(0);
default:
printf(“Enter correct choice”);
}
}
}

OUTPUT

1. Insert
2. Delete
3. Display
4. Exit
Enter your choice:1
Enter the value in queue:12

1. Insert
2. Delete
3. Display
4. Exit
Enter your choice:1
Enter the value in queue:23

1. Insert
2. Delete
3. Display
4. Exit
Enter your choice:1
Enter the value in queue:34

1. Insert
2. Delete
3. Display
4. Exit
Enter your choice:2
Deleted value is:12
1. Insert
2. Delete
3. Display
4. Exit
Enter your choice:1
Enter the value in queue:45

1. Insert
2. Delete
3. Display
4. Exit
Enter your choice:1
Enter the value in queue:56

1. Insert
2. Delete
3. Display
4. Exit
Enter your choice:3
Values are:23,34,45,56,
1. Insert
2. Delete
3. Display
4. Exit
Enter your choice:1

10 COMMENTS

  1. 100有機潤唇膏 雙頭磨沙滋潤豐唇膏 滋潤豐唇蜜 亮彩保濕口紅 亮彩保濕唇蜜 持久亮麗雙頭唇彩 唇線筆 唇膏筆 抗炎作用原理:內環境平衡,增強陰道內免疫力 CO2可本質的改變組織特性,使粘膜組織新生 陰道上皮細胞功能增強,大量糖原在陰道桿菌作用下分解成乳酸,逐步恢復陰道正常的PH值 免疫力增強,降低私密處感染

  2. I just want to tell you that I am very new to blogs and honestly savored you’re blog. More than likely I’m planning to bookmark your blog post . You really come with really good articles and reviews. Cheers for revealing your webpage.

  3. I would like to verbalize that I haven’t reviewed something so exciting in a while. There are many motivating ideas and opinions. I suppose that you absolutely stumbled upon an vital fact and I signed up to your rss feed to stay well-versed.

  4. I absolutely love your blog and find most of your post’s to be exactly I’m looking for. can you offer guest writers to write content for you personally? I wouldn’t mind composing a post or elaborating on many of the subjects you write about here. Again, awesome weblog!

LEAVE A REPLY

Please enter your comment!
Please enter your name here