| | |
doubly linked list--- help needed1
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: May 2006
Posts: 1
Reputation:
Solved Threads: 0
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) ;
}
}
#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) ;
}
}
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
These should be
to..
Error here - you can't redefine names. change to
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.
There appears to be a load of other errors too, such as:
These should be
C++ Syntax (Toggle Plain Text)
#include <iostream> #include <cctype> #include <string>
to..
C++ Syntax (Toggle Plain Text)
int main()
Error here - you can't redefine names. change to
C++ Syntax (Toggle Plain Text)
Name * Head = NULL; Name * Tail = NULL;
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)
std::string s1("James"); 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. ![]() |
Similar Threads
- Removing an item from head of linked list (C)
- Doubly Linked List Problem (C++)
- To create contact manager using doubly linked list(c++) (C++)
- "doubly linked list" question (C)
- How Can I Sort a Doubly Linked List Queue? (C)
- Need Help to Print Doubly Linked List(DLL) (Java)
- doubly linked list implementation (Java)
Other Threads in the C++ Forum
- Previous Thread: ignore function
- Next Thread: Problem converting Selection Sort to Class
| Thread Tools | Search this Thread |
api array based binary bitmap c++ c/c++ calculator char char* class classes code coding compile console conversion count database delete deploy desktop developer directshow dll download dynamic dynamiccharacterarray email encryption error file forms fstream function functions game givemetehcodez google graph gui homeworkhelp iamthwee ifstream input int java lib linkedlist linker linux list loop looping loops map math matrix memory multiple news node number numbertoword output pointer problem program programming project python random read recursion recursive reference return rpg sorting string strings temperature template templates test text text-file tree unix url variable vector video visualstudio win32 windows winsock word wordfrequency wxwidgets





