simple_bubble_sort.txt

来自「一个简单的字符冒泡排序例子」· 文本 代码 · 共 62 行

TXT
62
字号
//**************************************
//     
// Name: A Simple Bubble Sort
// Description:Sorts a pre-definied arra
//     y into order. My second submission under
//     the C++ section, and my second day of le
//     arning this language..so go easy :)
// By: Brutus
//
//This code is copyrighted and has// limited warranties.Please see http://
//     www.1CPlusPlusStreet.com/xq/ASP/txtCodeI
//     d.2966/lngWId.3/qx/vb/scripts/ShowCode.h
//     tm//for details.//**************************************
//     

#include <iostream.h>
#include <string.h>
#include <conio.h>
	//jumbled up text in array
	char strarray[] = "fgjhsflsdlkfghdksdkjdgskakdkfkjggkdkgjg";
	int i = 0;
	int j = 0;
	char temp;
	void Bubble(char* strarray, int arrsize);
	
int main()


    {
    cout << strarray << endl;
    Bubble(strarray, strlen(strarray));
    cout << strarray << endl;
    	
    return 0;
}
	
void Bubble(char* strarray, int arrsize) //Bubble Sort code


    {
    	for(i=0; i< (arrsize - 1); ++i)


        	{
        		for(j = i + 1; j > 0; --j)


            		{
            			if(strarray[j] < strarray[j-1])


                			{
                				//Swaps the values
                				temp = strarray[j];
                				strarray[j] = strarray[j - 1];
                				strarray[j - 1] = temp;
                			}
                			
                		}
                	}
            }

⌨️ 快捷键说明

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