欢迎您访问 最编程 本站为您分享编程语言代码,编程技术文章!
您现在的位置是: 首页

插入页眉和页尾--最好通过查看代码在纸上模拟这一过程。

最编程 2024-06-11 11:25:39
...
#include<bits/stdc++.h>
using namespace std
typedef struct Node
{
    int value;
    struct Node *next;
}node,*linkedlist;
linkedlist linkedlistcreath()//返回的是该链表的地址
{
    node *l=(node*)malloc(sizeof(node));
    l->next=NULL;
    int number;
    while (scanf("%d",&number)!=EOF)
    {
        node *p=(node*)malloc(sizeof(node));//新建一个node结构并为其申请空间
        p->value=number;//给新建的node结构赋值
        p->next=l->next;//赋值p所指的节点(就是l所指的节点,即链表的第2个节点)
        l->next=p;//将l所指的节点更新为p点
    }
    return l;//返回头节点地址
 
}

方法2:尾插法

推荐阅读