标题:关于排序的问题
取消只看楼主
瓦力
Rank: 2
等 级:论坛游民
帖 子:41
专家分:27
注 册:2011-11-18
结帖率:100%
已结贴  问题点数:5 回复次数:1 
关于排序的问题
程序代码:
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
struct stu{
    int num;
    struct stu * next;
};
void creat();
struct stu  *p, *q , *head, *tail;
int main(void)
{
    struct stu * head = NULL;

    creat();

    return 0;
}
void creat()
{
    int num, n = 0, i, j;
    int ptr;
    head = tail = NULL;

    int size = sizeof(struct stu);
    printf("input 0 end input and print link!\n");
    printf("input num:\n");
    scanf("%d",&num);
    do{
        p = (struct stu *)malloc(size);
        p->num = num;
        if(head == NULL)
            head = p;
        else
            tail->next = p;
        tail = p;
        p->next = NULL;
        printf("input number:\n");
        scanf("%d",&num);
        n++;
    }while(num != 0);
    p = head;
    q = p->next;
    for(i = 1;i< n; i++){
        for(j = 0; j<=n-i;j++){
            if(p->num >= q->num){
                ptr = p->num;
                p->num = q->num;
                q->num = ptr;
            }
            p=q;
            q=q->next;
        }
    }
    for(p = head;p;p=p->next)
        printf("%d",p->num);
}

问什么不能输出呢?
搜索更多相关主题的帖子: head next color 
2012-05-19 22:59
瓦力
Rank: 2
等 级:论坛游民
帖 子:41
专家分:27
注 册:2011-11-18
得分:0 
2012-05-20 11:23



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-367754-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 1.155095 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved