伊莎贝尔阿佳妮 衰老:寻求一个用头部插入结点法将输入的数按逆序输出的程序?

来源:百度文库 编辑:高校问答 时间:2024/04/27 23:17:14
用C++编一个将输入的数按逆序输出的完整的程序!
由于我是一个初学者,所以请各位不要见笑!
算法如下:
listlink createlist (int n)//逆序输入n个元素,建立带头结点的单链表L
{ int data;
linklist head;
listnode *p;
head=(linklist)malloc(sizeof(listnode));
if (head==NULL)
{ error (”No space for node can be obtained〃);
return ERROR;}
head->next=null; //建立一个带头结点空表
for(i=n;i>0;--i)

{
p=(listnode*)malloc(sizeof(listnode));
if (p==NULL)
{ error (”No space for node can be obtained
〃);
return ERROR;}
scanf(”%d〃,&p–>data); //从键盘输入元素的值
p–>next=head->next;
head->next=p; //把结点p插入到表头
}
}