-
Notifications
You must be signed in to change notification settings - Fork 0
/
combinedOpsLinkedList.c
86 lines (82 loc) · 1.68 KB
/
combinedOpsLinkedList.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
#include <stdio.h>
#include <stdlib.h>
struct node{
int data;
struct node *link;
}*front,*reer,*ptr;
int counts;
void insert(){
int value;
ptr=(struct node*)malloc(sizeof(struct node));
if(ptr==NULL){
printf("Queue overflow\n\n");
}
else{
printf("Enter a value you want to insert..");
scanf("%d", &value);
ptr->data=value;
ptr->link=NULL;
if(front==NULL){
front=reer=ptr;
}
else{
reer->link=ptr;
reer=ptr;
}
printf("\nNode inserted Successfully\n\n");
counts++;
display();
}
}
void delete(){
int val;
if(front==NULL){
printf("\nSorry! Queue is Empty\n\n");
}
else{
ptr=front;
front=front->link;
free(ptr);
printf("\nNode deleted Successfully\n\n");
counts--;
display();
}
}
void display(){
ptr=front;
if(front==NULL){
printf("\n\nQueue is Empty\n\n");
}
else{
printf("Queue is now having %d element(s) below: \n\n", counts);
while(ptr!=NULL){
printf("%d\n", ptr->data);
ptr=ptr->link;
}
}
}
void main(){
int choice;
printf("WELCOME TO OUR PROGRAM!\n\n");
do{
printf("Enter: \n 1.Insert\n 2.Delete\n 3.Display\n 0.Exit\n\n");
scanf("%d", &choice);
switch(choice){
case 1:
insert();
break;
case 2:
delete();
break;
case 3:
display();
break;
case 0:
printf("\n\nThank you for using our program. Bye!!\n");
return;
default:
printf("Invalid Choice. Try again\n\n");
}
}
while(choice!=0);
}