View Single Post
SlowToady SlowToady is offline
Registered
 
Join Date: Dec 2002
Location: www.fakelife.com
Posts: 1,672
Send a message via AIM to SlowToady
Um, anyone know how to control a Bubble Sort algorithm with a bool flag?

Code:
if (choice == 1)
	{
		//same comments from sort_array apply here
		for (unsigned short x = 0; x <= computer_count; x++)
		{
			for (unsigned short j = 0; j < computer_count - 1; j++)
			{
				if (computer[j].Brand > computer[j+1].Brand)
				{
					//This method of swapping is MUCH nice than using multiple arrays
					compdef temp; //create temporary struct
					temp = computer[j+1]; //copy entire struct
					computer[j+1] = computer[j];
					computer[j] = temp;
					//swap values around
				}
			}
		}
So that code like that would exit when there are no more swaps, instead of brute force going through all the iterations of the outer FOR loop?
__________________
I turn away with fear and horror from this lamentable sore of continuous functions without derivatives. --Charles Hermite

Fakelife.com Nothing to do with archery anymore. Porsche/BMW/Ferrari/Honda videos
Old 09-07-2007, 09:39 AM
  Pelican Parts Catalog | Tech Articles | Promos & Specials    Reply With Quote #5 (permalink)