⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 multidim_bsort.txt

📁 二维数组的冒泡排序
💻 TXT
字号:
//**************************************
//     
// Name: multi-dimensional array bubble 
//     sort
// Description:Source code to sort a mul
//     ti-dimensional array. Works with MSVC++ 
//     6.0 Not sure about other compilers.
// By: David Javaheri
//

// Page 284 Exercise 9 Bubble Sort for M
//     ulti-
//Dimensional Array
// Author - David Javaheri Date: 03/17/2
//     000
// Input - None
// Processing - Fill array with 200 rand
//     om values
//Sort the array 
// Output - arrray[10][20]
//moves
#include <iostream.h>
#include <iomanip.h>
#include <stdlib.h>
#include <time.h>
#include <process.h> 
#define MAX 500 //Highest possible value that
//can go into the array
#define MIN 1 //Lowest possible value that
//can go into the array
#define ORDER < //How you want the list sorted.
		 // < for smallest to largest
// > for largest to smallest
void main()


    {
    int i, j, l, array[10][20];
    int row, col, x, y=0, z;
    int temp, moves=0;
    srand((unsigned) time(NULL)); 
    x=101;
    
    for(row = 0; row < 10; row++;)


        {
        	for(col = 0; col < 20; col++)


            	{
            	 x = rand() % MAX + MIN;
            	 array[row][col] = x;
            	}
        }
        	
        for(row = 0; row < 10; row++) //displays the 
        //unsorted array


            {
            	for(col = 0; col < 20; col++)


                	{
                	 cout<<setw(3)<<array[row][col]<<" ";
                	}
                	cout<<endl;
            }
            cout<<"This is the original array"<<endl;
            cout<<"Enter any key"<<endl;
            cin>>l;
            system("cls"); //Clears the screen of the 
            //unsorted array
            for(i = 0; i < 200; i++)


                {	
                	z=1;
                	
                for(j = 0; j < 199; j++)	


                    	{
                    	 if(array[y][z] ORDER array[y][z - 1])


                        	 {
                        	 temp = array[y][z];
                        		array[y][z] = array[y][z - 1];
                        		array[y][z - 1]=temp;
                        		moves++;
                        	 }
                        	 z++;
                        	}
                    }
                    for(row = 0; row < 10; row++) //displays the 
                    //sorted array


                        {
                        	for(col = 0; col < 20; col++)


                            	{
                            	 cout<<setw(3)<<array[row][col]<<" ";
                            	}
                            	cout<<endl;
                        }
                        cout<<moves<<" moves where made to sort this 
                        <<list"<<endl;
                        cout<<"Enter any key"<<endl;
                        cin>>l;
                    }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -