CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2

Thread: linked objects

  1. #1
    Join Date
    May 1999
    Location
    wallingford, pennsylvania
    Posts
    70

    linked objects

    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;
    }



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


  2. #2
    Join Date
    May 1999
    Location
    wallingford, pennsylvania
    Posts
    70

    Re: linked objects

    sorry advanced people, this was supposed to go into the beginner file


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured