ASSIGN. 4 CS-392-TCPTUTOR

10
153

Algorithm for Circular 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

Algorithm for Insertion of element in a circular queue
Step 1: IF front=0 AND rear=max-1
print “Overflow”
goto Step 4
[End of IF]
Step 2: IF front=-1 AND rear=-1
SET front=0,rear=0
else
rear=(rear+1)%max
[End of IF]
Step 3: SET queue[rear]=value
Step 4: Exit

Algorithm for deletion in a circular queue
Step 1: IF front=-1
print “Underflow”
goto Step 4
Step 2: SET VAL=queue[front]
Step 3: IF front=rear
SET front=-1,rear=-1
else
front=(front+1)%max
[End fo IF]
Step 4: Stop

Algorithm for display the elements in circular queue
Step 1: IF front=-1 OR front==rear
print “Queue is empty”
goto step 3
[End of if]

Else goto step 2.
Step 2: IF front<rear
set i=front if i<=rear
print cqueue[i]
set i=i+1
else
IF front>rear
Set i=front
print cqueue[i]
set i=(i+1)%max if i!=rear+1
Step 3: stop

SOURCE CODE

#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
#define max 4
int cqueue[max];
int front=-1,rear=-1;
void enqueue(int value)
{
if((front==0&&rear==max-1)||(front==(rear+1)%max))
printf(“Overflow”);
else
{
if(front==-1&&rear==-1)
{
front++;
rear++;
}
else
rear=(rear+1)%max;
cqueue[rear]=value;
}
}
int dequeue()
{
if(front==-1)
printf(“Underflow”);
else
{
if(front==rear)
{
front=-1;
rear=-1;
}
else
{
printf(“Deleted value:%d”,cqueue[front]);
front=(front+1)%max;
}
}
return 0;
}
void display()
{
int i;
if(front==-1||front==rear)
printf(“Queue is empty”);
else
{
printf(“Elements are:”);
if(front<rear)
{
for(i=front;i<=rear;i++)
{
printf(“%d,”,cqueue[i]);
}
}
else
if(front>rear)
{
i=front;
do
{
printf(“%d,”,cqueue[i]);
i=(i+1)%max;
}
while(i!=rear+1);
}
}
}
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:
dequeue();
break;
case 3:
display();
break;
case 4:
exit(0);
default:
printf(“Enter correct choice”);
}
}
}

OUTPUT

1. Insert
2. Delete
3. Display
4. Exit
Enter yor choice:2
Underflow
MENU
Enter your choice:3
Queue is empty
MENU
Enter your choice:1
Enter the value in queue:11
MENU
Enter your choice:1
Enter the value in queue:22
MENU
Enter your choice:1
Enter the value in queue:33
MENU
Enter your choice:1
Enter the value in queue:44
MENU
Enter your choice:1
Enter the value in queue:55
Overflow
MENU
Enter your choice:3
Elements are:11,22,33,44,
MENU
Enter your choice:2
Deleted value:11
MENU
Enter your choice:2
Deleted value:22
MENU
Enter your choice:1
Enter the value in queue:55
MENU
Enter your choice:1
Enter the value in queue:66
MENU
Enter your choice:3
Elements are:33,44,55,66
MENU
Enter your choice:4

10 COMMENTS

  1. 【智慧魔鏡開箱】美麗時尚一鏡到底.介紹我的專屬高CP值美肌小秘書HiMirror.美魔女秘密武器 @ 潮流、美妝、消費 創造個人化風格的女性社群 PIXstyleMe 【智慧魔鏡開箱】美麗時尚一鏡到底.介紹我的專屬高CP值美肌小秘書HiMirror.美魔女秘密武器

  2. FineScan 會在肌膚上製造數以千計的細小深入傷口,即所謂的顯微加熱區(microthermal zone),但要確保每次治療時皆有部份組織不受能量影響,於是,每一個顯微加熱區的作用雖然強烈而明顯,但周圍都包覆著正常且結構完整的皮膚組織,使傷口能在短時間內癒合,並替換之前有缺陷的受損組織。Finescan不僅可讓表皮新生,更可促進深層膠原再生,從內而外徹底喚醒細胞,瞬時找回年輕時的肌膚狀態。憑藉最新的雙軸技術,FINESCAN 6可治療 – 面部 – 頸部 – 暗瘡凹凸洞 – 增生性疤痕

  3. 加強優化面部輪廓,可被身體完全吸引,能自然地修飾面部輪廓 功效可長達24個月以上 JUVEDERM的特點: 效果立即可見 非永久性 非手術性 安全有效 效果自然 JUVEDERM獲歐盟(CE)及美國及藥物管理局(FDA)認證 首先及唯一獲得FDA認證在首次療程後能維持長達一年2-4功效 新世代專員Hylacross科技為產品帶來獨特的物理特質,包括凝聚力、支撐力及柔順度 8點提升 這是一套由全球著名醫學美容醫生Dr. Maurício de Maio,以JUVÉDERM®系列透明質酸產品為基礎而研發的面部優化療程,藉著簡單程序便達致面部優化效果,不需進行手術,減低風險。 此療程會根據病人的個別情況,重點針對面部8個最常因流失膠原蛋白及彈性纖維而凹陷的位置,再依據特定的順序,從顴骨至下巴位置配合JUVÉDERM®系列的透明質酸產品進行療程,從而改善這些位置的豐盈度及滑溜度,全面性優化面部輪廓。

LEAVE A REPLY

Please enter your comment!
Please enter your name here