文章

28

粉丝

44

获赞

4

访问

6.1k

头像
单链表 题解:
P1015 贵州大学机试题
发布于2024年3月10日 17:23
阅读数 222

用数组保存输入的五个数,冒泡排序后再用尾插法插入链表,遍历链表

#include<stdio.h>
#include<stdlib.h>
int main()
{
    typedef struct LNode
    {
        int data; // 节点中的元素为整数类型
        struct LNode * next; // 指向下一个节点
    }LNode;

    LNode *p,*head,*tail;
    head=(LNode *)malloc(sizeof(LNode));
    head->next=NULL;
    tail=head;
    int a[5];
    int i,j,t;
    for(i=0;i<5;i++)
    {
        scanf("%d",&a[i]);
    }

    for(i=0;i<4;i++)//用冒泡排序从小到大排序
    {
        for(j=0;j<4-i;j++)
        {
            if(a[j]>a[j+1])
     ...

登录查看完整内容


登录后发布评论

暂无评论,来抢沙发