Advertisement
6_2008-2009 Sorting #198921

A Simple Bubble Sort

Sorts a pre-definied array into order. My second submission under the C++ section, and my second day of learning this language..so go easy :)

AI

Riepilogo AI: This codebase represents a historical implementation of the logic described in the metadata. Our preservation engine analyzes the structure to provide context for modern developers.

Codice sorgente
original-source
#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;
			}
			
		}
	}
}
Commenti originali (3)
Recuperato da Wayback Machine