| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 265 人关注过本帖
标题:谢谢你
只看楼主 加入收藏
于红光521
Rank: 1
等 级:新手上路
帖 子:12
专家分:0
注 册:2012-10-11
结帖率:75%
收藏
已结贴  问题点数:1 回复次数:1 
谢谢你
using System;
using System.Collections.Generic;
using System.Text;

namespace ConsoleApplication27
{
    class Program
    {
        static void Main(string[] args)
        {

            int[] arr = new int[] {1,5,6,9,2,45,36 };
            Console.Write("输出这组数");
            for (int i = 0; i < arr.Length - 1; i++)
            {

                System.Console.WriteLine(arr[i]);

            }
            
            foreach (int m in arr) {
                Console.Write(m +" ");
                Console.WriteLine();
                for (int i = 0; i < arr.Length - 1;i++ ) {
                    int j=i+1;
                id:  if (arr[i]>arr[j]){
                        int t;
                        t = arr[i];
                        arr[i] = arr[j];
                        arr [i+1]=t;
                        goto id;
                }
                    else
                        if (j < arr.Length-1) {

                            j++;
                            goto id;
                        }
         

                           
                }
  foreach (int n in arr ){


      Console.Write(n+" ");
      Console.WriteLine("排序之后的数组");
      for (int i = 0; i < arr.Length - 1; i++) {

          System.Console.WriteLine(arr [i]);
      
      }
      System.Console.ReadLine();
  }
                    




                    
                    
                    
                    }
               
               
                }
            }
        }
   

搜索更多相关主题的帖子: void 
2012-10-13 13:52
lybh24
Rank: 8Rank: 8
等 级:贵宾
威 望:19
帖 子:120
专家分:701
注 册:2012-9-8
收藏
得分:1 
(⊙o⊙)上次那段代码写的有些问题,这是我改了下的
  class Program
    {
        static void Main(string[] args)
        {
           
            int[] arr = new int[] { 1, 5, 6, 9, 2, 45, 36 };
            foreach (int n in arr)
            {
                Console.WriteLine(n);
            }
            Console.WriteLine("排序后");
            GotoOrderBind(ref arr);
            foreach (int n in arr)
            {
                Console.WriteLine(n);
            }
            Console.ReadKey();
        }

        private static void GotoOrderBind(ref int[] arr)
        {
            int j = 0;
            for (int i = 0; i < arr.Length - 1; i++)
            {
                j = i + 1;
            id: if (arr[i] > arr[j])
                {
                    int t = arr[i];
                    arr[i] = arr[j];
                    arr[j] = t;

                    goto id;
                }
                else
                    if (j < arr.Length - 1)
                    {
                        j++;
                        goto id;
                    }
            }
        }
    }

[ 本帖最后由 lybh24 于 2012-10-15 09:09 编辑 ]

新群:273209143
2012-10-13 15:15
快速回复:谢谢你
数据加载中...
 
   



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

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