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

📄 simple_bubble_sort.txt

📁 一个简单的字符冒泡排序例子
💻 TXT
字号:
//**************************************
//     
// 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 + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -