I have to modify this program which uses templates to use only linked lists and I am having a world of trouble trying to figure out how to start. I am quite horrible with linked lists and would appreciate any kind of help. It is n implementation file that recieves any kind of data and then sorts it. And I can't figure out how I would make a linked list do that. Or what kind of code I would write to make it do that. I have read a couple of chapters in my C++ book and they are anything but helpful. I have spent a couple of days working on it and this is my last resort. Thanks.
Code:#include <iostream> using namespace std; template<class ItemType> GLista<ItemType>::GList() //Constructor { length = 0; sorted = false; } template<class ItemType> bool GLista<ItemType>::IsEmpty() const { return(length == 0); } template<class ItemType> bool GLista<ItemType>::IsFull() const { return(length == MAX_LENGTH); } template<class ItemType> int GLista<ItemType>::Length() const { return length; } template<class ItemType> void GLista<ItemType>::Insert(/* in */ ItemType item) { data[length] = item; length++; sorted = true; } template<class ItemType> void GLista<ItemType>::Delete(/* in */ ItemType item) { int index = 0; while(index < length && item != data[index]) index++; if(index < length) { if(sorted) { while(index <= length - 2) { data[index] = data[index + 1]; index++; } } else data[index] = data[length - 1]; length--; } } template<class ItemType> bool GLista<ItemType>::IsPresent(/* in */ ItemType item) const { int index = 0; while(index < length && item != data[index]) index++; return(index < length); } template<class ItemType> void GLista<ItemType>::SelSort() { ItemType temp; int passCount; int searchIndex; int minIndex; for(passCount = 0; passCount < length - 1; passCount++) { minIndex = passCount; for(searchIndex = passCount + 1; searchIndex < length; searchIndex++) if(data[searchIndex] < data[minIndex]) minIndex = searchIndex; temp = data[minIndex]; data[minIndex] = data[passCount]; data[passCount]= temp; } sorted = true; } template<class ItemType> void GLista<ItemType>::Print() const { int index; for(index = 0; index < length; index++) cout << data[index] << endl; }



LinkBack URL
About LinkBacks



I used to be an adventurer like you... then I took an arrow to the knee.