最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

在C中对整数列表进行排序

SEO心得admin130浏览0评论
本文介绍了在C中对整数列表进行排序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

给定一组整数,如何在C 中编写程序,使用C对这些整数进行排序,给出以下条件 a。不要使用数组 b。不要使用任何比较功能,如if / then 或switch-case c。你只能使用指针 d。你也不能使用任何循环。

Given a set of integers, how to write a program in C to sort these set of integers using C, given the following conditions a. Do not use arrays b. Do not use any comparison function like if/then or switch-case c. you can use pointers only d. you cannot use any of the loops either.

推荐答案

使用qsort() aruna写道: Use qsort() aruna wrote: 给定一组整数,如何在C中编写程序,使用C对这些整数进行排序,给出以下条件 a。不要使用数组 b。不要使用任何比较功能,如if / then 或switch-case c。你只能使用指针 d。你也不能使用任何一个循环。 Given a set of integers, how to write a program in C to sort these set of integers using C, given the following conditions a. Do not use arrays b. Do not use any comparison function like if/then or switch-case c. you can use pointers only d. you cannot use any of the loops either.

- 从地址删除.spam以通过电子邮件回复。

-- remove .spam from address to reply by e-mail.

ar********@yahoo.co。在(aruna)写道: ar********@yahoo.co.in (aruna) writes: 给定一组整数,如何用C语言编写一个程序,用C对这些整数进行排序,给定以下条件不要使用数组 b。不要使用任何比较功能,如if / then 或switch-case c。你只能使用指针 d。你不能使用任何一个循环。 Given a set of integers, how to write a program in Cto sort these set of integers using C, given the following conditions a. Do not use arrays b. Do not use any comparison function like if/then or switch-case c. you can use pointers only d. you cannot use any of the loops either.

为什么一些大学教授继续设置这样不切实际的作业 问题!?为什么不让学生质疑这些问题的不切实际性? __________________________________________________ _____________________________ 克里斯麦克唐纳博士EMAIL: ch *** @ csse.uwa.edu.au 计算机科学与技术学院软件工程 西澳大利亚大学WWW: www.csse.uwa.edu.au/~chris 克劳利,西澳大利亚州,6009 PH:+61 8 6488 2533,传真:+61 8 6488 1089

Why do some College professors continue to set such unrealistic homework questions!? Why don''t students question the unrealistic nature of these questions? __________________________________________________ _____________________________ Dr Chris McDonald EMAIL: ch***@csse.uwa.edu.au School of Computer Science & Software Engineering The University of Western Australia WWW: www.csse.uwa.edu.au/~chris Crawley, Western Australia, 6009 PH: +61 8 6488 2533, FAX: +61 8 6488 1089

2004-04-24,James McIninch< ja ************ @ comcast.spam>写道: [由AutoTopPostIncinerator X ++ Professional Edition修复的热门帖子] On 2004-04-24, James McIninch <ja************@comcast.spam> wrote: [Top posting fixed by "AutoTopPostIncinerator X++ Professional Edition" ] aruna写道: aruna wrote: 给定一组整数,如何用C语言编写程序来使用C对这些整数进行排序,鉴于以下条件 a。不要使用数组 b。不要使用任何比较功能,如if / then 或switch-case c。你只能使用指针 d。你也不能使用任何一个循环。 Given a set of integers, how to write a program in C to sort these set of integers using C, given the following conditions a. Do not use arrays b. Do not use any comparison function like if/then or switch-case c. you can use pointers only d. you cannot use any of the loops either.

使用qsort()

Use qsort()

对,但另一块拼图如何在不使用循环的情况下吸收输入 ? 我想我可以用这样的递归作弊: #include< stdio.h> int read_one_int(FILE * fp,int * i) { int v = fscanf(fp,"%d",i); return(v!= 0&& v!= EOF); } int read_all_ints(FILE * fp,int * v,unsigned num) { 返回num&& read_one_int(fp,v)&& read_all_ints(fp,v + 1,num-1); } - James

Right, but the other piece of the puzzle is how to absorb the input without using a loop? I suppose I could cheat with recursion like this: #include <stdio.h> int read_one_int(FILE *fp, int *i) { int v = fscanf(fp, "%d", i); return (v != 0 && v != EOF); } int read_all_ints(FILE *fp, int *v, unsigned num) { return num && read_one_int(fp, v) && read_all_ints(fp, v+1, num-1); } -- James

发布评论

评论列表(0)

  1. 暂无评论