-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPBSLL.C
187 lines (168 loc) · 2.51 KB
/
PBSLL.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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdbool.h>
#include <conio.h>
struct node{
int val;
char lname[50];
char fname[50];
char mname[30];
char pnum[16];
char bday[40];
struct node *next;
};
typedef struct node NODE;
NODE *head = NULL, *curr = NULL;
menu()
{
clrscr();
gotoxy(24, 10);
printf("Phone Book SLL");
gotoxy(24, 11);
printf("[1] Insert");
gotoxy(24, 12);
printf("[2] Destroy");
gotoxy(24, 13);
printf("[3] Remove");
gotoxy(24, 14);
printf("[4] Search");
gotoxy(24, 15);
printf("[5] Exit");
gotoxy(24, 16);
printf("Choice: ");
}
NODE* create(int val)
{
NODE *ptr;
clrscr();
gotoxy(24, 10);
printf("Creating NODE @ [%d]", val);
if(NULL == ptr)
{
gotoxy(24, 11);
printf("Failed to create NODE");
return NULL;
}
ptr->val = val;
ptr->next;
head = curr = ptr;
sleep(1);
return ptr;
}
destroy(NODE *L)
{
return 0;
}
NODE* insert(int val, char lname[], bool add)
{
NODE * ptr;
if(NULL == head)
{
return (create(val));
}
if(add)
{
clrscr();
gotoxy(24, 11);
printf("Adding to end..");
sleep(1);
}
else
{
clrscr();
gotoxy(24, 11);
printf("Adding to beginning..");
sleep(1);
}
ptr = (NODE *)malloc(sizeof(NODE));
if(NULL == ptr)
{
clrscr();
gotoxy(24, 11);
printf("Creation failed..");
sleep(1);
return NULL;
}
ptr->val = val;
ptr->next = NULL;
if(add)
{
curr->next = ptr;
curr = ptr;
}
else
{
ptr->next = head;
head = ptr;
}
getch();
return ptr;
main();
}
/*
void remove(char *data, NODE *L)
{
return 0;
}
*/
search(char *data, NODE *L)
{
return 0;
}
main()
{
int choice;
char i, x, lname[50], fname[50], mname[50], pnum[16], bday[40];
NODE temp, *L;
clrscr();
menu();
gotoxy(24+9, 16);
scanf("%i", &choice);
if(i <= 0)
i++;
switch(choice)
{
case 1:
clrscr();
gotoxy(24, 10);
printf("Add new Contact");
gotoxy(24, 11);
printf("Last Name:");
gets(temp.lname);
gotoxy(24, 12);
printf("First Name: ");
gets(temp.fname);
gotoxy(24, 13);
printf("Middle Name: ");
gets(temp.mname);
gotoxy(24, 14);
printf("Phone Number: ");
gets(temp.pnum);
gotoxy(24, 15);
printf("Birthday (MM/DD/YYYY): ");
gets(temp.bday);
insert(i, lname, true);
break;
case 2:
destroy(L);
break;
case 3:
/*remove(x, L);*/
break;
case 4:
search(x, L);
break;
case 5:
gotoxy(24, 19);
printf("BYE -BYE!");
sleep(2);
return 0;
default:
gotoxy(24, 19);
printf("Invalid choice!");
main();
break;
}
}