-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathhello.c
95 lines (86 loc) · 1.41 KB
/
hello.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
static int j;
int q[5];
char lo[1000]="";
char v[50];
void push(int item){
system("clear");
if(j>=5)
printf("Stack overflow\n");
else {
q[j]=item;
printf("\nadded %d at index %d",item,j);
sprintf(v,"\nadded %d at index %d",item,j);
strcat(lo,v);
j++;
}
}
void showlog(){
system("clear");
printf("\n--------------LOG---------------");
printf("%s\n",lo);
printf("--------------------------------\n");
}
int pop(){
system("clear");
int item;
if(j<=0){
printf("Stack underflow\n");
return 0;
}
else {
j--;
item=q[j];
q[j]=0;
printf("removed %d at index %d",item,j);
sprintf(v,"\nremoved %d at index %d",item,j);
strcat(lo,v);
return item;
}
}
void display(){
system("clear");
int i;
printf("{");
for (i = 0; i < 5; i++){
printf("%d, ",q[i]);
}
printf("}");
}
int menu(){
int a;
printf("\n\n Choose operation: 1)Push 2)Pop 3)Display 4)Log 5)Exit: ");
scanf("%d",&a);
return a;
}
main() {
system("clear");
int choice,qw;
printf("Welcome to the demonstration of queue");
while(1){
choice=menu();
switch(choice){
case 1:
printf("\nEnter item to push : ");
scanf("%d",&qw);
push(qw);
break;
case 2:
pop();
break;
case 3:
display();
break;
case 4:
showlog();
break;
case 5:
exit(0);
default:
system("clear");
printf("\nWrong choice!");
}
}
}