?? simple_bubble_sort.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 + -