| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 399 人关注过本帖
标题:新人求助:声明的函数无法调用,编译没有出错,不知道为什么运行到sort()就 ...
只看楼主 加入收藏
platinan
Rank: 1
等 级:新手上路
帖 子:1
专家分:0
注 册:2012-3-25
收藏
 问题点数:0 回复次数:1 
新人求助:声明的函数无法调用,编译没有出错,不知道为什么运行到sort()就直接跳过了
程序代码:
//排序一系列行数据,数据有n行,每行有1-50个数,以-1结尾
#include <stdio.h>

int sortnum[1000][50];
int priority[1000]; //大小优先矩阵,位子越前面越小

void sort(int lb,int hb);
bool comp(const bool &n1,const bool &n2);  //声明比较函数和排序函数

int main(int argc, char* argv[])
{    int n,p,i,j,count; //p
    int firstprint=1;
    scanf("%d",&n); //忽略第一行
    while(scanf("%d",&n))
    {    for(i=0;i<n;i++)
        {    priority[i]=i;
            count=0;
            while(scanf("%d",&p))     //读取数据
            {    sortnum[i][count++]=p;
                if(p==-1)
                    break;
            }
        }
        sort(0,n-1);   //排序,但在我用的visual studio 2008中执行没有跳到sort子函数中,求解
        for(i=0;i<n;i++) //输出
        {    firstprint=1;
            for(j=0;sortnum[priority[i]][j]!=-1;j++)
            {    if(firstprint==1)
                    firstprint=0;
                else printf(" ");
                printf("%d",sortnum[priority[i]][j]);
            } //for j
            printf("\n");
        } //for i
    } //while
    return 0;
}

void sort(int lb,int hb)  //排序函数,快速排序
{    int t,i=lb,j=hb,count=0;
    if(i<j)
    {    t=priority[lb];
        while(i<j)
        {    while(i<j)
                if(comp(t,priority[j])==0)
                    j--;
                else
                {    priority[i]=priority[j];
                    i++;
                    break;
                }
            while(i<j)
                if(comp(t,priority[i])==1)
                    i++;
                else
                {    priority[j]=priority[i];
                    j--;
                    break;
                }
        }//i<j
        priority[i]=t;
        sort(lb,i-1);
        sort(i+1,hb);
    }
}

bool comp(const bool &n1,const bool &n2) //比较函数,优先比较行序列第一个数
{    int count=0;
    while(sortnum[n1][count]==sortnum[n2][count])
        if(sortnum[n1][count]!=-1)
            count++;
        else break;
    return sortnum[n1][count]!=sortnum[n2][count]?sortnum[n1][count]>sortnum[n2][count]:sortnum[n1][count]>sortnum[n2][count];
}
搜索更多相关主题的帖子: 函数 声明 include 
2012-03-25 11:21
xiaoseqingch
Rank: 2
等 级:论坛游民
帖 子:36
专家分:42
注 册:2010-6-19
收藏
得分:0 
我调试了。。发现肯定是调用了sort()。。是你的排序方法有问题。。建议百度一下冒泡排序法。
2012-11-05 20:48
快速回复:新人求助:声明的函数无法调用,编译没有出错,不知道为什么运行到sor ...
数据加载中...
 
   



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

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