#pragma once
#include <stdio.h>
#include <stdlib.h>
#define count 10
typedef struct nodelist {
int data;
struct nodelist* next;
}list;
list* head;
void init() {
head = (list*)malloc(sizeof(list));
list *p = head;
list* np = NULL;
int i = 0;
while(p !=NULL) {
p->data = i;
if (i < count - 1) {
np = (list*)malloc(sizeof(list));
}
else {
np = NULL;
}
p->next = np;
p = np;
i++;
}
}
void print() {
list * p = head;
while (p != NULL) {
printf("%d\n", p->data);
p = p->next;
}
}
void reverse() {
list* p = head;
list* pre = NULL;
list* cur = NULL;
while (p != NULL) {
cur = p;
p = p->next;
cur->next = pre;
pre = cur;
}
head = cur;
}
void del_node(list* del) {
list* p = head;
if (head == del) {
head = del->next;
}
list* pre = NULL;
while(p != NULL && p != del) {
pre = p;
p = p->next;
}
if (p!=NULL && pre!= NULL) {
pre->next = p->next;
}
free(p);
}
void del_index(int n) {
int i = 0;
list* p = head;
while (i++ != n) {
p = p->next;
}
del_node(p);
}
- 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