sdut 链表lab1

简介: sdut 链表lab1

7-1 sdut-C语言实验-顺序建立链表

分数 20

全屏浏览

切换布局

作者 马新娟

单位 山东理工大学

输入N个整数,按照输入的顺序建立单链表存储,并遍历所建立的单链表,输出这些数据。

输入格式:

第一行输入整数的个数N;

第二行依次输入每个整数。

输出格式:

输出这组整数。

输入样例:

8
12 56 4 6 55 15 33 62

输出样例:

12 56 4 6 55 15 33 62

代码长度限制

16 KB

时间限制

400 ms

内存限制

64 MB

栈限制

8192 KB

#include <stdio.h>
#include <stdlib.h>
struct node{
int data;
struct node*next;
 
};
int main()
{
    int n,i;
    scanf("%d",&n);
    struct node *p,*tail,*head;
    head=(struct node*)malloc(sizeof(struct node));
    head->next=NULL;
    tail=head;
    for(i=0;i<n;i++)
    {
        p=(struct node*)malloc(sizeof(struct node));
        p->next=NULL;
        scanf("%d",&p->data);
        tail->next=p;
        tail=p;
 
    }
    p=head->next;
    while(p!=NULL)
    {
        if(p->next==NULL)
        {
         printf("%d\n",p->data);
        }
        else{
            printf("%d ",p->data);
        }
        p=p->next;
    }
 
}


目录
相关文章
|
1月前
|
存储
sdut 链表5
sdut 链表5
31 1
|
1月前
sdut 链表4
sdut 链表4
23 1
|
1月前
sdut链表lab2
sdut链表lab2
27 1
|
1月前
【移除链表元素】LeetCode第203题讲解
【移除链表元素】LeetCode第203题讲解
|
17天前
|
存储 SQL 算法
LeetCode力扣第114题:多种算法实现 将二叉树展开为链表
LeetCode力扣第114题:多种算法实现 将二叉树展开为链表
|
17天前
|
存储 SQL 算法
LeetCode 题目 86:分隔链表
LeetCode 题目 86:分隔链表
|
22天前
|
存储 算法 Java
【经典算法】Leetcode 141. 环形链表(Java/C/Python3实现含注释说明,Easy)
【经典算法】Leetcode 141. 环形链表(Java/C/Python3实现含注释说明,Easy)
10 2
|
1月前
<数据结构>五道LeetCode链表题分析.环形链表,反转链表,合并链表,找中间节点.
<数据结构>五道LeetCode链表题分析.环形链表,反转链表,合并链表,找中间节点
24 1
|
14天前
|
算法
【经典LeetCode算法题目专栏分类】【第7期】快慢指针与链表
【经典LeetCode算法题目专栏分类】【第7期】快慢指针与链表
|
17天前
|
存储 SQL 算法
LeetCode 83题:删除排序链表中的重复元素【面试】
LeetCode 83题:删除排序链表中的重复元素【面试】