I'm working on a homework assignment, I have to make a program that balances Chemical Equations. I've got most of the work done but my program requires that both sides of the equation be in the same order.
To do this I figured I would sort them into alphabetical order. I wrote up some code to do this(listed below).
I really need some help because its due in a couple of days, can someone tell me what I am doing wrong.
Its an Insertion sort, the code should be fairly explanatory.
thanks for your help.
Code:short CStore::AlphaSort() { int i = 0; //Loop Varibles int k = 0; char key = 0; // current value working on for(i = 1; i <= EleNum; i++) { key = CStore::Element[i].Capital; k = i-1; cout << "A" << key << "|" << i << "|" << k << endl; ////////////////////// while( CStore::Element[k].Capital > key) //go through { //move a value up one in the list CStore::Element[k+1].ChemNum = CStore::Element[k].ChemNum; CStore::Element[k+1].Capital = CStore::Element[k].Capital; CStore::Element[k+1].LCase = CStore::Element[k].LCase; CStore::Element[k+1].Amount = CStore::Element[k].Amount; cout << "B" << key << "|" << i << "|" << k << endl; if(k == 0) //when loop reaches bottom { cout << "C" << key << "|" << i << "|" << k << endl; CStore::Element[k].ChemNum = CStore::Element[i].ChemNum; CStore::Element[k].Capital = CStore::Element[i].Capital; CStore::Element[k].LCase = CStore::Element[i].LCase; CStore::Element[k].Amount = CStore::Element[i].Amount; } k--; } ////////////////////// CStore::Element[k+1].ChemNum = CStore::Element[i].ChemNum; CStore::Element[k+1].Capital = CStore::Element[i].Capital; CStore::Element[k+1].LCase = CStore::Element[i].LCase; CStore::Element[k+1].Amount = CStore::Element[i].Amount; cout << "D" << key << "|" << i << "|" << k << endl; } //////////////////////////////////////////////// PrintArray("After Sort:"); ///////////////////////////////////////////////////////// return 1; }



LinkBack URL
About LinkBacks


