Hi, I have to implement a class called linked list that must read from file the following information about persons: name, social security and age. Then I have to implement some methods for manipulate the data. The problem is that I don't know how to start the implementation, because I have to create a Class Person then a Class List and use them? How?

Any suggestion will be appreciated.

Read you text book to see how to create a class. Then you can use google to find examples of a linked list class. The Person class should be straight forward -- just follow the example in your text book of in any of the hundreds of tutorials you can find on the net.

After you get started post the code you have done and we'll be glad to help you out.

Read you text book to see how to create a class. Then you can use google to find examples of a linked list class. The Person class should be straight forward -- just follow the example in your text book of in any of the hundreds of tutorials you can find on the net.

After you get started post the code you have done and we'll be glad to help you out.

typedef int ElementType;

class LinkedList
{
      private:
              class Node
              {
                    public:
                           Node *next;
                           ElementType info;
                  
              };
              typedef Node * Nodeptr;
      
      public: 
             LinkedList(); // constructor
             ~LinkedList(); // destructor
             
             bool in_list(ElementType, Nodeptr&);
             bool empty();
             
             void display(ostream & out); 
             void erase(ElementType);
             void insert(ElementType);

      private:
              int mySize; // number of nodes
              Nodeptr myFirst; //  point to first node. 
             
};

ostream & operator<<(ostream & out, const LinkedList & aList);

Then I'm supposed to read the information about the person. I must create a class person, but I don't what I must do later?

Where did you get that linked list? the class Node doesn't make sense because it doesn't contain any data other than an integer that says what kind of data its supposed to contain.

The implementation is in the main() program. Create an instance of the linked list class, add several Person objects to it, delete a Person object, print all of them, etc. Before you can do any of that you have to create the Person class and its methods.

Where did you get that linked list? the class Node doesn't make sense because it doesn't contain any data other than an integer that says what kind of data its supposed to contain.

The implementation is in the main() program. Create an instance of the linked list class, add several Person objects to it, delete a Person object, print all of them, etc. Before you can do any of that you have to create the Person class and its methods.

I got it from my book ADTs, Data Structures, and Problem Solving with C++ of Larry Nyhoff.

class Person
{
      public:
             Person();
             
      private: 
               string name,
                      ss;
               int age;
};

Before I can use an instances of Class Linked List to manipulate an object of type Person I must change something in Class Linked List?

BTW I getting error from this Linked List method:

bool LinkedList::in_list(ElementType item, Nodeptr & anterior)
{ // in_list began
	Nodeptr p = myFirst,
            anterior = NULL; // previous
            
	while ( (p!=NULL) && (item > p->info) )
	{
		anterior = p;
		p = p->next;
	}
	if ( (p==NULL) || (item < p->info) ) 
		return false;
	else 
         return true;
} // in_list end

Line 33 declaration of 'LinkedList::Node*anterior' shadows a parameter

Thanks -

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.