Hey. I'm trying to simply input items into a list, then be able to sort them and do whatever. I've done this before for my previous classes, but we have we have to use class files out of the book and modify them to make this work and I'm having way too much trouble. If somebody could point me in the right direction, it would be much appreciated.

I created the .cpp file. The unsorted.h is from the book. There are a couple of more files, let me know if they are needed.

// This is the .cpp file.
#include "unsorted.h"
#include <iostream>
using namespace std;

int main()
{
	UnsortedType list;
	ItemType  item;
	list.MakeEmpty();
	item.Initialize();
	
		cout << "Enter number (-999 to quit): ";
		cin >> item;
 			list.InsertItem(item);
		
}
// This is the unsorted.h file.
#include "itemtype.h"

class UnsortedType
{
public:
	UnsortedType();
	bool IsFull() const;
	int LengthIs() const;
	void RetrieveItem(ItemType& item, bool& found);
	void InsertItem(ItemType item);
	void DeleteItem(ItemType item);
	void ResetList();
	void MakeEmpty();
	void GetNextItem(ItemType& item);
private:
	int length;
	ItemType info[MAX_ITEM];
	int currentPos;
};

Why are you using 'ItemType' for your lists? Is this some sort of generic container-type object? (Presumably it overloads the '>>' operator, since you were using it in main().) If I were designing the UnsortedType class, I would probably use a template so the object type can be specified when a new instance of the class is defined.

It also seems a bit of a waste the way you store and pass objects, if it's possible, try passing by reference so you don't end up with as much overhead on the stack (since you're going to have to copy the object into the internal array anyway).

That's exactly what I was thinking. The directions specifically said to put the input data into an "item", then put the item in the list. Right now I keep getting errors when I use the "cin >> item" then try to store that into the list. I just get an ItemType error. What exactly do I have to initialize in the "item.Initialize(????)" to get this to work. This whole method of doing this seems messed up.

>Right now I keep getting errors when I use the "cin >> item"
Well, then clearly you haven't overloaded the '>>' operator for ItemType.

>What exactly do I have to initialize in the "item.Initialize(????)"
>to get this to work.
You've never posted how ItemType was defined, so can't help you there. Either make due with the current ItemType structure (perhaps modify it if you're allowed), or you're going to have to use a different structure to hold your list nodes, such as an integer.

This article has been dead for over six months. Start a new discussion instead.