#include <stdio.h>
#include <stdlib.h>//创建空间
typedef struct Sq {
int data;
struct Sq* next;
}Sq;
Sq* Initlist() {
Sq* list = (Sq*)malloc(sizeof(Sq));
list->data = 0;
list->next = NULL;
return list;
}
void ListheadInsert(Sq* list, int data) {
Sq* node = (Sq*)malloc(sizeof(Sq));
node->data = data;
node->next = list->next;
list->next = node;
list->data++;
}
void ListtailInsert(Sq* list, int data) {
Sq* head = list;
Sq* node = (Sq*)malloc(sizeof(Sq));
node->data = data;
node->next = NULL;
list = list->next;
while (list->next) {
list = list->next;
}
list->next = node;
head->data++;
}
void ListDelete(Sq* list, int data) {
Sq* node = list->next;
Sq* prior = list;
while (node) {
if (node->data == data) {
prior->next = node->next;
free(node);
break;
}
prior = node;
node = node->next;
}
list->data--;
}
void ListPrint(Sq* list) {
list = list->next;
while (list) {
printf_s("%d", list->data);
list = list->next;
}
printf_s("NULL\n");
}
int main()
{
Sq* list = Initlist();
ListheadInsert(list, 1);
ListtailInsert(list, 2);
ListPrint(list);
ListDelete(list, 1);
ListPrint(list);
return 0;
}