Solved

linked list

Posted on 2004-04-06
2
189 Views
Last Modified: 2013-12-14
/********************************reservation class******************/

class Reservation {      //private members
private:
      Date      compare;
      Date      res_made;
      Date      pick_up;
      Date      due_back;
      int            con_months;
      enum      truck_type {Toyota, Nissan, Acura} trucks;
      //char*      truck_des[];
      
public:                  //public members/funcions
      Reservation      *next;
      Reservation();
      ~Reservation();
      void res_date (Date);
      void set_con (int);
      void set_dueback (Date);
      void print (void);
      void res_compare(void);
      //Date res_date (Date);
};



/*****************************future.h file******************************/

#include "res_header.hpp"

class future
{
private:
            
            Reservation* list;
            Reservation* leader;
            Reservation* follower;
            Reservation* tail;
            int count;
      
      public            
            create_list(Reservation*);
            locate();
            insert();
            void print(){cout<<"testing future"<<endl;}
            future();
            ~future();
}

/*************************************future.cpp file******************/
#include "res_header.hpp"
#include "future.hpp"


      future()
      {
            list==NULL;
            leader==NULL;
            follower==NULL;
            count=0;
      }

      void create_list(Reservation *temp, Reservation temp_reserve_data)
      {
            
            temp=new Reservation;
            temp=temp_reserve_data;
            if(list==NULL)
            {
                  list=temp;
                  leader=temp;
                  follower=temp;
                  tail=temp;
            }
            else

                  while(tail->    // ********here when I write tail-> the list is not
//getting displayed. How to write a linked list. Could you please tell me how to write a linked list in a c++. I know it in c. I am  not able to do it in c++. */
                  /*if (temp->compare ==1)
                  {
                        
                  }*/

      }
0
Comment
Question by:rmvprasad
2 Comments
 

Author Comment

by:rmvprasad
ID: 10770720
Here future and reservation are classes. so I want to know how to do linked list of classes.
0
 
LVL 15

Accepted Solution

by:
lakshman_ce earned 30 total points
ID: 10770802
Use STL list class for this

The STL list class is a template class of sequence containers that maintain their elements in a linear arrangement and allow efficient insertions and deletions at any location within the sequence. The sequence is stored as a bidirectional linked list of elements, each containing a member of some type Type.

template <
   class Type,
   class Allocator=allocator<Type>
>
class list
Parameters
Type
The element data type to be stored in the list. (can be future or reservation class types)
Allocator
The type that represents the stored allocator object that encapsulates details about the list's allocation and deallocation of memory. This argument is optional, and the default value is allocator<Type>.


You can refer to the code for insert at
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vcstdlib/html/vclrflistmerge.asp
Also you can refer to
http://www.sgi.com/tech/stl/Slist.html
http://www.sgi.com/tech/stl/List.html

-Lakshman
0

Featured Post

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
FMX enumerated colours 2 98
Eclipse Neon start with Admin account only 6 123
Problem with SqlConnection 4 168
What is sub-make ? 2 58
  Included as part of the C++ Standard Template Library (STL) is a collection of generic containers. Each of these containers serves a different purpose and has different pros and cons. It is often difficult to decide which container to use and …
C++ Properties One feature missing from standard C++ that you will find in many other Object Oriented Programming languages is something called a Property (http://www.experts-exchange.com/Programming/Languages/CPP/A_3912-Object-Properties-in-C.ht…
The viewer will learn how to use and create new code templates in NetBeans IDE 8.0 for Windows.
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

776 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question