doubly linked list--- help needed1

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: May 2006
Posts: 1
Reputation: jack11b is an unknown quantity at this point 
Solved Threads: 0
jack11b jack11b is offline Offline
Newbie Poster

doubly linked list--- help needed1

 
0
  #1
May 4th, 2006
hi im having problems with a doubly linked list. im trying to initialise three names into the list and print them straight off using the list and pointers but cant figure out how. heres what i have already if it could be modified i would greatly appreciate. also please keep the explanations simple as i have only recently started c++

#include <iostream.h>
#include <ctype.h>
#include <string.h>

void initialise(Name *&, char arr[], Name *&);
void DisplayList(Name *) ;
main()
{
Name * Head, * Tail ;
Name *Head = NULL,
*Tail = NULL;
Name *mvlr=NULL;

char s1[]="name1";
char s2[]="name2";
char s3[]="name3";

initialise(s1, Head, Tail);
initialise(s2, Head, Tail);
initialise(s3, Head, Tail);
DisplayList(Head) ;
}

void initialise(Name * &H, Name * &T)
{ H = T = NULL ;
}

void DisplayList(Name * H)
{ ListEntry *curr = H ;
if(H != NULL) {
do {
cout << curr->Name << endl ;
curr = curr->Next ;
}while(curr != H) ;
}
}
Reply With Quote Quick reply to this message  
Join Date: Feb 2006
Posts: 486
Reputation: Bench has a spectacular aura about Bench has a spectacular aura about Bench has a spectacular aura about 
Solved Threads: 48
Bench's Avatar
Bench Bench is offline Offline
Posting Pro in Training

Re: doubly linked list--- help needed1

 
0
  #2
May 4th, 2006
You've only just started C++ and you're trying to implement a doubly linked list? You might want to start out with a singly linked list first... Also, it's hard to see exactly what is supposed to be going on in your code without seeing the definition of Name

  1. #include <iostream.h>
  2. #include <ctype.h>
  3. #include <string.h>
These should be
  1. #include <iostream>
  2. #include <cctype>
  3. #include <string>

  1. main()
to..
  1. int main()

  1. Name * Head, * Tail ;
  2. Name *Head = NULL,
  3. *Tail = NULL;
Error here - you can't redefine names. change to
  1. Name * Head = NULL;
  2. Name * Tail = NULL;

  1. char s1[]="name1";
  2. char s2[]="name2";
  3. char s3[]="name3";
This is OK, but you might be making life difficult for yourself. I recommend you use the C++ std::string instead of C-Style null-terminated char arrays.
  1. std::string s1("James");
  2. std::string s2("Kevin"); //etc


There appears to be a load of other errors too, such as: cout << curr->Name << endl ; but it's impossible to tell what's going on without seeing what Name actually is.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC