-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlinked_list.c
More file actions
127 lines (114 loc) · 2.55 KB
/
Copy pathlinked_list.c
File metadata and controls
127 lines (114 loc) · 2.55 KB
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
#include<stdio.h>
#include<stdlib.h>
#include "linked_list.h"
int countC();
void deleteC2(char* num)
{
struct nodeC **indirect=&userDisplayList;
struct nodeC *temp=NULL;
while(*indirect!=NULL){
if(strcmp((*indirect)->data,num)==0){
temp=*indirect;
*indirect=(*indirect)->next;
free(temp);
} else{
indirect=&((*indirect)->next);
}
}
return;
}
void insertC(char *name)
{
struct nodeC *temp, *mp3;
mp3 = (struct nodeC *) malloc(sizeof(struct nodeC)); // malloc space for MP3
mp3->data = (char *) malloc(strlen(name) + 1); // malloc space for name
strcpy(mp3->data, name); // "assign" name via copy
mp3->next = NULL;
if (headC == NULL)
{
headC = mp3; // add the first MP3
}
else
{
temp = headC;
while (temp->next != NULL)
temp = temp->next;
temp->next = mp3; // append to the tail/end
}
}
void deleteC(char* num)
{
struct nodeC **indirect=&headC;
struct nodeC *temp=NULL;
while(*indirect!=NULL){
if(strcmp((*indirect)->data,num)==0){
temp=*indirect;
*indirect=(*indirect)->next;
free(temp);
} else{
indirect=&((*indirect)->next);
}
}
return;
}
void displayC(struct nodeC *r)
{
r=headC;
if(r==NULL)
{
return;
}
while(r!=NULL)
{
printf("%s ",r->data);
r=r->next;
}
printf("\n");
}
int countC()
{
struct nodeC *n;
int c=0;
n=headC;
while(n!=NULL)
{
n=n->next;
c++;
}
return c;
}
void freeallC(){
struct nodeC *temp=headC;
while(headC!=NULL){
temp=headC;
headC=headC->next;
free(temp->data);
free(temp);
}
struct nodeC *tempList=userDisplayList;
while(userDisplayList!=NULL){
tempList=userDisplayList;
userDisplayList=userDisplayList->next;
free(tempList->data);
free(tempList);
}
}
void insertC2(char *name)
{
struct nodeC *temp, *mp3;
mp3 = (struct nodeC *) malloc(sizeof(struct nodeC)); // malloc space for MP3
mp3->data = (char *) malloc(strlen(name) + 1); // malloc space for name
strcpy(mp3->data, name); // "assign" name via copy
mp3->next = NULL;
if (userDisplayList == NULL)
{
userDisplayList = mp3; // add the first MP3
}
else
{
temp = userDisplayList;
while (temp->next != NULL)
temp = temp->next;
temp->next = mp3; // append to the tail/end
}
}