Click to See Complete Forum and Search --> : linked objects


Hyena
October 26th, 1999, 09:38 AM
the other day i asked if it was possible to make a linked list of objects ( with the object being-

class oneCard {
public:
char *face;
char *suit;
int value;
};

i know that to make this object into a linked list, i need to add oneCard *next into the class definition. however, i wasnt able to modify my linked list to accept the three variables like i needed. could someone please show me how? i provided the linked list i wrote (i'll admit i had help).




#include <iostream.h>

//-------------------------------class intList--------------------------------
class list {
public:
int number;
list *next;
};
//----------------------------------------------------------------------------


//-------------------------function getNumber---------------------------------
int getNumber()
{
int x;

cout << "What is the number?\n";
cin >> x;

return x;
}
//---------------------------------------------------------------------------


//===========================================================================
//--------------------------------main---------------------------------------
//---------------------------------------------------------------------------
void main ()
{
int num;

list *listPtr;
list *lastPtr = 0;
list *first = 0;


while (num = getNumber())
{
listPtr = new list;


listPtr->number = num;
listPtr->next = 0;

if(lastPtr)
lastPtr->next = listPtr;
else
first = listPtr;

lastPtr = listPtr;
}


if(first) {
cout << "The list is ";
listPtr = first;

do {
cout << listPtr->number << " ";
listPtr = listPtr->next;
}while(listPtr);

cout << endl;
}



}
//----------------------------------------------------------------------------
//----------------------------------------------------------------------------
//============================================================================

Hyena
October 26th, 1999, 09:40 AM
sorry advanced people, this was supposed to go into the beginner file