天天看点

单链表头结点后插入元素及遍历单链表educoder

//遍历单链表,请把代码补全
void PrintList(Node *first)
{
	Node *p;
	p=first->next;
	while(p)
	{
		printf("%d ",p->data);
		p=p->next;
	}
	printf("\n");
}
/*本函数的功能是在头结点后面插入一个新结点,结点的数据域的值为x*/
void InsertAtHead(Node *first,DataType x)
{
    Node *T;
	T=(Node *)malloc(sizeof(Node));
    T->data=x;
    T->next=first->next;
    first->next=T;
    
}