-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdelete.c
64 lines (56 loc) · 1.17 KB
/
delete.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
//#ifndef _FUNCTION_H_
//#define _FUNCTION_H_
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
//define basic headfiles
#include "functions.h"
//define custom headfiles
void print_list(struct task *head,struct task *end)
{
struct task *p = head;
while(p != ((end)->next)){
printf("%d,%s,%s,%s,%d",p -> id,p -> name,p-> mail,p -> group,p -> sex);
printf("\n");
p = p -> next;
}
}
void delete_list(struct task **top,struct task **end,int num)
{
struct task *temp = (*top);
struct task *temp_front = NULL;
if (temp -> id == num){
(*top) = temp->next;
free(temp);
printf("delete %d success\n",num);
return;
} else {
while ((temp != NULL) && (temp->id != num)){
temp_front = temp;
temp = temp -> next;
}
if (temp == NULL){
printf("cant find\n");
return;
} else {
temp_front -> next = temp -> next;
free(temp);
printf("delete %d success\n",num);
}
}
}
void clear_list(struct task **head,struct task **end)
{
struct task *p = NULL;
while((*head) != NULL)
{
p = (*head);
(*head) =(*head) -> next;
free(p);
}
(*head) == NULL;
(*end) == NULL;
if (*head == NULL){
printf("clear\n");
}
}