944,123 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Unsolved
  • Views: 2394
  • C++ RSS
May 4th, 2006
0

doubly linked list--- help needed1

Expand Post »
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) ;
}
}
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
jack11b is offline Offline
1 posts
since May 2006
May 4th, 2006
0

Re: doubly linked list--- help needed1

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

Quote ...
C++ Syntax (Toggle Plain Text)
  1. #include <iostream.h>
  2. #include <ctype.h>
  3. #include <string.h>
These should be
C++ Syntax (Toggle Plain Text)
  1. #include <iostream>
  2. #include <cctype>
  3. #include <string>

Quote ...
C++ Syntax (Toggle Plain Text)
  1. main()
to..
C++ Syntax (Toggle Plain Text)
  1. int main()

Quote ...
C++ Syntax (Toggle Plain Text)
  1. Name * Head, * Tail ;
  2. Name *Head = NULL,
  3. *Tail = NULL;
Error here - you can't redefine names. change to
C++ Syntax (Toggle Plain Text)
  1. Name * Head = NULL;
  2. Name * Tail = NULL;

Quote ...
C++ Syntax (Toggle Plain Text)
  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.
C++ Syntax (Toggle Plain Text)
  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.
Reputation Points: 307
Solved Threads: 62
Posting Pro
Bench is offline Offline
565 posts
since Feb 2006

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C++ Forum Timeline: ignore function
Next Thread in C++ Forum Timeline: Problem converting Selection Sort to Class





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC