鱼C论坛

 找回密码
 立即注册
查看: 3780|回复: 1

C语言链表怎么从大到小输出

[复制链接]
发表于 2012-12-8 21:52:36 | 显示全部楼层 |阅读模式
5鱼币
#include "stdio.h"
int k(struct str *c);
struct str
{
char name[5];
int n;
struct str *next;
}ne[5]={{"555",5},{"666",6},{"777",7},{"888",8}};
void main()
{
struct str *p=NULL;
p=&ne[0];
  ne[0].next=&ne[1];
  ne[1].next=&ne[2];
  ne[2].next=&ne[3];
  ne[3].next=&ne[4];
  ne[4].next=NULL;
k(p);
}
int k(struct str *c)
{
struct str  *p=NULL;
p=c;
printf("%s %d\m",p->name,p->n);
return 0;
}

把上面代码 改成 从大到小输出
应该怎么改

最佳答案

查看完整内容

/* ** 双向链表test */ #include "stdio.h" int k(struct str *c); struct str { char name[5]; int n; struct str *next; struct str *pre; }ne[5]={{"555",5},{"666",6},{"777",7},{"888",8}}; void main() { struct str *p=NULL; struct str *tail=NULL; //尾指针 p=&ne[4]; tail=&ne[4]; ne[0].next=&ne[1]; ne[1].next=&ne[2]; ne[2].next=&ne[3]; ne[3].next=&ne[4]; ne[4].next=NULL; ...
小甲鱼最新课程 -> https://ilovefishc.com
发表于 2012-12-8 21:52:37 | 显示全部楼层
/*
** 双向链表test
*/
#include "stdio.h"
int k(struct str *c);
struct str
{
        char name[5];
        int n;
        struct str *next;
        struct str *pre;
}ne[5]={{"555",5},{"666",6},{"777",7},{"888",8}};
void main()
{
        struct str *p=NULL;
        struct str *tail=NULL; //尾指针
        p=&ne[4];
        tail=&ne[4];
        ne[0].next=&ne[1];
        ne[1].next=&ne[2];
        ne[2].next=&ne[3];
        ne[3].next=&ne[4];
        ne[4].next=NULL;
        ne[4].pre =&ne[3];
        ne[3].pre =&ne[2];
        ne[2].pre =&ne[1];
        ne[1].pre =&ne[0];
        ne[0].pre =NULL;
        k(p);
}
int k(struct str *c)
{
        int i;
        struct str  *p=NULL;
        p=c;
        for(i=0;i<5;i++,p--)
        {
                printf("%s %d\n",p->name,p->n);
        }
        return 0;
}
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2025-11-16 18:51

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表