sti.h下:
#include<stdio.h>
#include<stdlib.h>
typedef struct node
{
int date;
struct node* next; //指向下一个节点的指针
}NODE;
NODE* head = NULL; //定义头指针
NODE* creatlist();
NODE* creatNode();
void printflist(NODE* headnode);
void insertnode(NODE* headnode, int date);
#include"sti.h"
int main()
{
NODE* list = creatlist();
insertnode(list, 1);
insertnode(list, 2);
insertnode(list, 3);
printflist(list);
return 0;
}
NODE* creatNode(int date)
{
NODE* newnode = (NODE*)malloc(sizeof(NODE));
newnode->date = date;
newnode->next = NULL;
return newnode;
};
NODE* creatlist() //创建新结点或说创建链表
{
NODE* newnode = (NODE*)malloc(sizeof(NODE)); //创建新结点
newnode->next = NULL; //让newnode这个结点指向空
return newnode;
}
void insertnode(NODE* headnode, int date) //插入结点,参数:所要插入的链表,所要插入的结点的数据
{
NODE* newnode = creatlist(); //创建插入的结点
headnode->next = newnode; //newnode放在headnode后面
newnode->next = headnode->next; //newnode放在headnode->next后面
}
void printflist(NODE * headnode) //打印结点
{
NODE * pmove= headnode->next;
while (pmove)
{
printf("%d", pmove->date);
pmove = pmove->next;
}
printf("\n");
}
执行时是死循环,怎么修改?