C++数据结构链表基本操作示例过程

首先创建好一个节点

```typedef struct node {
int date;
struct node* next;
}*PNODE;
PNODE creatnode(int date )
{
PNODE newnode = (PNODE)malloc(sizeof(struct node));
assert(newnode);
newnode->next = NULL;
newnode->date = date;
return newnode;
}
```

其次创建一个统计节点属性

```struct List {
struct node* pronode;//这只是一个类型
struct node*tailnode;
int size;
};
//创建统一链表属性的list
//用来统计链表的（size）节点数
struct List* creatlist()
{
struct List* list = (struct List*)malloc(sizeof(struct List));
assert(list);
list->pronode = NULL;
list->tailnode = NULL;
list->size = 0;//初始化
return  list;

}```

增加节点

用表头插入的方法插入节点

```​void insertbyhead(struct List* list,int date)
{
PNODE newnode = creatnode(date);
if (list->size == 0)
{
list->pronode = list->tailnode = newnode;
}
else
{
newnode->next = list->pronode;
list->pronode = newnode;
}
list->size++;
}

​```

删除节点

```//表头删除
{
PNODE next = list->pronode->next;
free(list->pronode);
list->pronode = next;
}
//表尾删除
void deletetail(struct List* list)
{
PNODE pmove = list->pronode;//定义一个移动指针
//目的找到表尾指针
if (list->size == 0)
{
printf("无法删除");
return;
}
while (pmove->next != list->tailnode)
{
pmove = pmove->next;
}
pmove->next = NULL;//表尾指针前面一个下一个指向null
free(list->tailnode);
list->tailnode = pmove;

}```