相信自己!

  BlogJava :: 首页 :: 新随笔 :: 联系 :: 聚合  :: 管理 ::
  26 随笔 :: 3 文章 :: 13 评论 :: 0 Trackbacks
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication2
{
    
class Program
    
{
        
//int num = 0;
        static void Main(string[] args)
        
{
            Stack
<string> aa = new Stack<string>();
            aa.Push(
"111");
            aa.Push(
"222");
            aa.Push(
"333");
            
//int num = aa.Count;
            for (int i = 0; i < aa.Count; i++)
            
{
                string bb 
= aa.Pop();
                Console.WriteLine(bb);
            }

            Console.Read();

        }

        
    }

}






using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication2
{
    
class Program
    
{
        
//int num = 0;
        static void Main(string[] args)
        
{
            
int[] ss = new int[] 12,3,67,22,89,102,2,54};
            Console.WriteLine(
"原始数据如下:");
            
for (int k = 0; k < ss.Length; k++)
            
{
                Console.Write(ss[k] 
+ "    ");
            }

            Console.WriteLine(
"  ");
            sort(ss, 
07,0);
            
            Console.Read();
        }

        
public static void sort(int[] array, int left, int right,int num)
        
{
            
            
int i, j;
            
int middle, t;
            i 
= left;
            j 
= right;
            middle 
= array[(left + right) / 2];
            
do
            
{
                
//从左侧找大于中间值的数
                while ((array[i] < middle) && (i < right))
                
{
                    i
++;
                }

                
//从右侧找小于中间值的数
                while ((array[j] > middle) && (j > left))
                
{
                    j
--;
                }

                
//找到了一对就交换
                if (i <= j)
                
{
                    t 
= array[i];
                    array[i] 
= array[j];
                    array[j] 
= t;
                    i
++;
                    j
--;
                    num 
= num + 1;
                    Console.WriteLine(
"第{0}次排序的结果", num);
                    
for (int k = 0; k < array.Length; k++)
                    
{
                        Console.Write(array[k] 
+ "    ");
                    }

                    Console.WriteLine(
"  ");
                }

            }
 while (i <= j); 
            
if (left < j)
            
{
                sort(array, left, j,num);
            }

            
if (right> i)
            
{
                sort(array, i, right,num);
            }

        }

    }

}
posted on 2008-04-29 16:18 北极雪 阅读(238) 评论(0)  编辑  收藏 所属分类: c#

只有注册用户登录后才能发表评论。


网站导航: