| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1245 人关注过本帖
标题:初学C#写了一段排序代码 各位看看到底算是冒泡还是选择
取消只看楼主 加入收藏
xboxeer
Rank: 1
等 级:新手上路
帖 子:1
专家分:0
注 册:2009-7-22
结帖率:0
收藏
已结贴  问题点数:20 回复次数:0 
初学C#写了一段排序代码 各位看看到底算是冒泡还是选择
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication8
{
    class Program
    {
        static void Main(string[] args)
        {
            int inumber;
            string strchoice;
            Console.WriteLine("type in the number of the numbers you want");
            inumber = Int32.Parse(Console.ReadLine());
            fh();
            px(inumber);
            fh();
            
            do
            {
                Console.WriteLine("again");
                Console.WriteLine("press y to continue");
                strchoice = Console.ReadLine();
                if (strchoice == "y" || strchoice == "Y")
                {
                    Console.WriteLine("type in the number of the numbers you want");
                    inumber = Int32.Parse(Console.ReadLine());
                    fh();
                    px(inumber);
                    fh();
                }
                else
                    break;
            }
            while (strchoice != "y" || strchoice!="Y");
            Console.WriteLine("press any key to exit");
        }
        static void px(int j)
        {//赋值
            int imin;
            int itemp;
            int[] ainumber = new int[j];
            for (int i = 0; i < ainumber.Length; i++)
            {
                Console.WriteLine("type in the number you want");
                ainumber[i] = Int32.Parse(Console.ReadLine());
            }
            //排序
            for (int i = 0; i < j; i++)
            {
               
                imin = i;
                itemp = ainumber[i];
                for (int k = i+1; k < j; k++)
                {
                    if (ainumber[imin] > ainumber[k])
                    {
                        itemp = ainumber[imin];
                        ainumber[imin] = ainumber[k];
                        ainumber[k] = itemp;
                    }
                }
               
               
            }
            fh();
            for (int i = 0; i < ainumber.Length; i++)
            {
                Console.WriteLine(ainumber[i]);
            }
            fh();
        }
        static void fh()
        {
            Console.WriteLine("*******************************************************");
           
        }
   
    }
}

写实照着选择排序的算法来的 后来看看觉得好像是冒泡了~

PS,写完这段正在写插入排序了 没有头绪 有没有哪位高手给点指导啊
搜索更多相关主题的帖子: 冒泡 代码 初学 选择 
2009-07-22 16:05
快速回复:初学C#写了一段排序代码 各位看看到底算是冒泡还是选择
数据加载中...
 
   



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

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