-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtodo_list_using_linkedlist.c
142 lines (130 loc) · 2.84 KB
/
todo_list_using_linkedlist.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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
/*to do list using linked list concept */
#include <stdio.h>
#include <stdlib.h>
void create();
void del();
void see();
void fixcount();
struct ToDo{
char data[100];
struct ToDo *link;
int count;
};
struct ToDo *start=NULL;
int main(){
int choice;
while(1){
system("cls");
printf("\t#################################### YOUR TODO LIST APP ##############################################\n\n");
printf("\n\t1.Create Your ToDos");
printf("\n\t2.Delete Your ToDos");
printf("\n\t3.See Your ToDo List");
printf("\n\t4.Exit");
printf("\n--------------------------------------------------------------------------------------------------");
printf("\n\nEnter your choice..");
scanf("%d",&choice);
switch(choice){
case 1:
create();
break;
case 2:
del();
break;
case 3:
see();
break;
case 4:
printf("Thank you !");
exit(0);
default:
printf("Enter correct option");
}
}
}
void see(){
system("cls");
struct ToDo *temp;
temp=start;
printf("\t***Your Todo's are***\n");
if(start==NULL){
printf("\nEmpty TODO\n\n");
}
printf("---------------------------------------\n");
while(temp!=NULL){
printf("\t%d)",temp->count);
puts(temp->data);
fflush(stdin);
temp=temp->link;
}
printf("\n-------------------------------------\n");
system("pause");
}
void create(){
system("cls");
char k;
struct ToDo *t,*temp;
while(1){
printf("\nWant to add?y/n : ");
fflush(stdin);
scanf("%c",&k);
if(k=='n')
break;
else{
if(start==NULL){
t=(struct ToDo *)malloc(sizeof(struct ToDo));
start=t;
printf("\nADD It Below.. : \n");
fflush(stdin);
gets(t->data);
t->count=1;
start->link=NULL;
}
else{
temp=(struct ToDo *)malloc(sizeof(struct ToDo));
printf("\nADD it..\n");
fflush(stdin);
gets(temp->data);
temp->link=NULL;
t->link=temp;
t=t->link;
}
fixcount();
}
}
}
void del(){
system("cls");
int d;
struct ToDo *temp1,*temp;
printf("\nEnter the no of the todo you want to remove\n");
scanf("%d",&d);
temp1=start;
temp=start->link;
while(1){
if(temp1->count==d){
start=start->link;
free(temp1);
fixcount();
break;
}
if(temp->count==d){
temp1->link=temp->link;
free(temp);
fixcount();
break;
}else{
temp1=temp;
temp=temp->link;
}
}system("pause");
}
void fixcount(){
struct ToDo *temp;
int i=1;
temp=start;
while(temp!=NULL){
temp->count=i;
i++;
temp=temp->link;
}
}