Thread: Linked list/Doubly linked list

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date
    Oct 2011
    Posts
    13
    Quote Originally Posted by iMalc View Post
    The code for the member functions looks good.

    The problem looks to be that head is not initialised to NULL. You're also storing a head inside every node. You're almost there with splitting the thing up into a node class and a list class. I'll help you get the rest of the way when I get home tonight.
    Should head be declared in public? I'm kinda confused about where to put it.


    Quote Originally Posted by Elysia View Post
    Are you using Visual Studio? If so, it might be a good time to learn the debugger. It's very simple and will help you a lot. I'd try using it to check for the problem iMalc mentioned. Nothing better than practice.
    Also, a double linked list is the same as a linked list - except it goes in both directions - back and forth, while a single linked list only goes forward.
    I'm not too familiar with the debugger.

  2. #2
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Quote Originally Posted by UserName112 View Post
    I'm not too familiar with the debugger.
    Get familiar! That's all I'm saying.
    You will need it in the future. Why wait, when it can make life so much easier?
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  3. #3
    Algorithm Dissector iMalc's Avatar
    Join Date
    Dec 2005
    Location
    New Zealand
    Posts
    6,318
    Okay, here's the main change to split 'list' and 'node' apart:
    Code:
    template <typename T>
    class node
    {    
    	T nodeValue;  
    	node<T> *next;
    public:
    	node() : next(NULL)
    	{}
    
    	node(const T& item, node<T> *nextNode = NULL) : 
    		nodeValue(item), next(nextNode)
    	{}
    };
    
    template <typename T>
    class list
    {    
    	node<T> *head;
    public:
    	void addAtFront(const T val);
    	void addAtBack(const T val);
    	void outputList() const;
    };
    My homepage
    Advice: Take only as directed - If symptoms persist, please see your debugger

    Linus Torvalds: "But it clearly is the only right way. The fact that everybody else does it some other way only means that they are wrong"

  4. #4
    Registered User
    Join Date
    Oct 2011
    Posts
    13
    I replaced the code and got an error saying that it could not access "next" because it was a private member. So I tried putting it into the public section and now there's no compile error, but I'm getting the ''Linked list.exe has encountered a problem" error with a blank screen as output.

    Get familiar! That's all I'm saying.
    You will need it in the future. Why wait, when it can make life so much easier?
    Is this a good tutorial to start out with?
    http://www.codeproject.com/KB/cs/Mas...Debugging.aspx
    Last edited by UserName112; 12-09-2011 at 07:09 PM.

  5. #5
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Quote Originally Posted by UserName112 View Post
    Yes, that looks like a good tutorial.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Help with my doubly linked list
    By evildotaing in forum C++ Programming
    Replies: 3
    Last Post: 11-29-2011, 11:47 AM
  2. doubly linked list
    By BEN10 in forum C Programming
    Replies: 4
    Last Post: 07-21-2009, 09:32 AM
  3. Doubly-Linked List
    By jgs in forum C Programming
    Replies: 7
    Last Post: 04-18-2005, 01:39 PM
  4. singly linked list to doubly linked list
    By t48j in forum C Programming
    Replies: 3
    Last Post: 03-23-2005, 06:37 PM
  5. Doubly Linked List.. please Help!!
    By ProgrammingDlux in forum C++ Programming
    Replies: 8
    Last Post: 10-24-2004, 08:27 PM