zoukankan      html  css  js  c++  java
  • 学习C#之旅 魔泡排序

    今天来谈谈冒泡,这可不是QQ群冒泡,呵呵!标题改成“魔炮”,比较时尚,是吧!忽悠园友一次。
    冒泡排序的关键代码
    for(i=0;i<scores.Length-1;i++)
    {
       
    for(j=0;j<scores.Length-1-i;j++)
       {
          
    if(scores[j]>scores[j+1])
          {
            temp
    =scores[j];
            scores[j]
    =scores[j+1];
            scores[j
    +1]=temp;
          }
       }
    }
    Console.WriteLine(
    "排序");
    for(i=0;i<scores.Length;i++)
    {
       Console.Write(
    "{0}\t",scores[i])
    }
    Console.ReadLine();

    scores是一个存放数据的数组。
    很难理解,我就给个例子吧!code如下:
    int[] price=new int[];
    int i,j,temp;
    int sum=0;

    string[] name=new string[7]{"CPU","内存","硬盘","显卡","光驱","主机","显示器"};

    for(i=0;i<=6;i++)
    {
      Console.Write(
    "请输入{0}价格:\t",name[i]);
      price[i]
    =int.parse(Console.ReadLine());
    }
    for(i=0;i<price.Length-1;i++)
    {  
       
    for(price[j]>price[j+1])
       {
         
    if(price[j]>price[j+1])
         {
           temp
    =price[j];
           price[j]
    =price[j+1];
           price[j
    +1]=temp;
         }
       }
    }
    Console.WriteLine(
    "DIY电脑计算价格报价单");
    for(i=o;i<price.Length;i++)
    {
       Console.WriteLine(
    "{0}价格:{1}\t",name[i],price[i]);
       sum
    =sum+price[i];
    }
    Console.WriteLine(
    "电脑总价格:"+sum);
    Console.ReadLine();
    code是手写的,未调试的,有错还请园友提出哦!
  • 相关阅读:
    前端使用crypto.js进行加密
    浅谈 Angular 项目实战
    YAML快速入门
    Preloading Your ASP.NET Applications
    ETL利器Kettle实战应用解析系列一【Kettle使用介绍】
    HBase
    hdfs知识点《转》
    Flume概念与原理、与Kafka优势对比《转》
    scrapy 快速入门
    比较好的算法网站
  • 原文地址:https://www.cnblogs.com/cube/p/1540886.html
Copyright © 2011-2022 走看看