Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% ont trouvé ce document utile (0 vote)
8 vues5 pages

Task 5 Ds

Télécharger au format pdf ou txt
Télécharger au format pdf ou txt
Télécharger au format pdf ou txt
Vous êtes sur la page 1/ 5

Coding C RUN MENU

Auto saved at 23:27:29

1 #include<stdio.h>
2 #define MAX 5
3
4 int cqueue_arr[MAX];
5 int front = -1;
6 int rear = -1;

7
8/*Begin of insert*/
9 Void insert(int item)
10 {
11 if((front ==
0 && rear ==
MAX-1) |||
12 Overflow \n");
13 printf("Queue
14 return;
15
16 if (front == -1) /*If queue is emp
17 {
18
18
front =
0;
19 rear = 0;

20
21 elsee
22
MAX-1)/*rear is at last
23 if(rear ==

rear = 0;
24
25 else
rear = rear+1;
26
27 }
28 Cqueue_arr[rear] =item
29
30/*End of insert*/
31
32/*Begin of del*/
33 Void del()|
34

Tab
Coding C RUN MENU
Auto saved at 23:27:29
0 printT(ELement deieted Trom queue
1 if(front == rear) /* queue has only
12 {
13 front = -1;
14 rear=-1;

16 else
17 if(front == MAX-1)
18
19 front = 0;

50 else
51 front = front+1;

52 }
53 }
54 /*End of del() */
55
56/*Begin of display* /
57 void display()
58 {
59 int front_pos = front, rear_pos = re
60 if(front ==
-1)
61 {
62 printf("Queue is empty\n'");
63 return;
64
65 printf("Queue elements : \n");
66 if front_pos = rear_pos )
67
while(front_pos <=
rear_pos)
68 {
69
printf("%d",cqueue_arr[front_pos
70 front_pos++;
71
72 else
73
7 Arhile(front noc <= MAX-1)
Tab
&
Auto saved at
23:27:29 RUN MENU
78
79

80
front_pos =
0;
81 while(front_pos
{
<=
rear__pos)
82
83
printf("%d ",cqueue_arr[front_pos]
84
front_pos++;
85
86 p r i n t f ( " \ n " ) ;

87

88/*End of display*/
89

90/*Begin of main*/
91
int ma
92
in ( )
93 int choice,item;
94 do
95
96
97 printf("1.Insert\n")
printf("2. Delete\n");
98 printf("3.Display\n");
99 printf("4.Quit\n" );
100
101
102
printf("Enter your choice:");
scanf("%d" ,&choice);
103
104 switch(choice)
105 {
106 Case 1
107 printf("Input the element for in
108
109
scanf(%d", &item);
110
insert(item);
111 break;
Tab

&
Coding C
RUN MENU
Auto saved at 23:27:29

95 {
96 printf("1.Insert\n");
97 printf("2.Delete\n");
98 printf("3 .Display\n");
99 printf("4.Quit\n");
100
101 printf("Enter your choice ");
102
102 Scanf("%d",&choice);
103
104 switch ( choice)
105
106 case 1
the element for ins
107 printf("Input
108
Scanf("%d", &item);
109
110 insert(item);
111 break;
112 case 2
113 del():
114 break;
case 3:
115
116 displayO;
117 break;
Case 4:
118
break;
119
default:
printf("Wrong choice\n");
120
121
122 =4) ;
123 while(choice !
124
125 return 0
126
26 _ fmain*|
Compile Result

1.Insert
2.Delete
3.Display
4.Quit
Enter your choice : 1
Input the element for insertion in qu
2ue 3
1.Insert
2.Delete
3.Display
4.Quit
Enter your choice: 3

Queue elements5
3
1.Insert
2.Delete
3.Display
4.Quit
Enter your choice

GIF

1 2 3 4 5 67 8 9 0

W e t yui o p

asdfgh k
Z X C V b n m
#1 English (US)

Vous aimerez peut-être aussi