Thread: Doubly Linked List Node

  1. #1
    Registered User
    Join Date
    Mar 2007
    Posts
    109

    Doubly Linked List Node

    Hey i'm trying to create a header file for a doubly linked list node. So far i have
    Code:
    #ifndef DLLISTNODE_H
    #define DLLISTNODE_H
    #include <iostream>
    
    using namespace std;
    
    template <class T>
    class DLListNode
    {
        public:
                     DLListNode();
                     DLListNode(const T&)
                     DLListNode(const T&, DLListNode<T>*
                     ~DLListNode();
                     void set(data, nextPtr, prevPtr)
                     void retrieve(data)
    
        private:
                     T data;
                     DLListNode<T>* nextPtr;
                     DLListNode<T>*prevPtr;
    };
    #include "DLListNode.template"
    #endif
    can someone let me know if any of this is right. The Set funtion is supposed to set the private data members, the retreive is supposed to retreive the private data members. And I need a constructor that allows a node to be immediately linked into a list. I have them in there just not sure if they are right.
    Last edited by DarkDot; 04-15-2007 at 11:10 PM.

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Code:
    DLListNode(const T&)
    DLListNode(const T&, DLListNode<T>*
    Looks like two typographical errors (missing terminating semi-colon and the the second constructor prototype I listed looks half finished). It would be good to give a name to the parameters to as to hint at what they are intended for.

    Code:
    void set(data, nextPtr, prevPtr)
    void retrieve(data)
    More typographical errors (missing terminating semi-colon), and more importantly, it looks like you are now providing names to the parameters, but forgot about the types.

    Incidentally, remove the "using namespace std;" from your header file. Use fully qualified names in header files.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    Registered User
    Join Date
    Mar 2007
    Posts
    109
    I've never not used namespace std in my header before. do i need the iostream there? and does everything else look right and do what i said in the previous one needed to do?

    Code:
    #ifndef DLLISTNODE_H
    #define DLLISTNODE_H
    #include <iostream>
    
    using namespace std;
    
    template <class T>
    class DLListNode
    {
        public:
                     DLListNode();
                     DLListNode(const T&)
                     DLListNode(const T&, DLListNode<T>*);
                     ~DLListNode();
                     void set(T data, DLListNode<T>* nextPtr, DLListNode<T>* prevPtr);
                     void retrieve(T data);
    
        private:
                     T data;
                     DLListNode<T>* nextPtr;
                     DLListNode<T>*prevPtr;
    };
    #include "DLListNode.template"
    #endif

  4. #4
    Just Lurking Dave_Sinkula's Avatar
    Join Date
    Oct 2002
    Posts
    5,005
    Tell me, what here requires either <iostream> or using namespace std;?
    Code:
    template <class T>
    class DLListNode
    {
        public:
                     DLListNode();
                     DLListNode(const T&)
                     DLListNode(const T&, DLListNode<T>*);
                     ~DLListNode();
                     void set(T data, DLListNode<T>* nextPtr, DLListNode<T>* prevPtr);
                     void retrieve(T data);
    
        private:
                     T data;
                     DLListNode<T>* nextPtr;
                     DLListNode<T>*prevPtr;
    };
    If your answer is "nothing", then the question is why?

    Only to present extraneous problems to some code that includes it? Doesn't that sound like a reason to ditch it?
    7. It is easier to write an incorrect program than understand a correct one.
    40. There are two ways to write error-free programs; only the third one works.*

  5. #5
    Registered User
    Join Date
    Mar 2007
    Posts
    109
    ok but everything else is correct? likes is the T data const T& data? or wat it is now?

  6. #6
    Just Lurking Dave_Sinkula's Avatar
    Join Date
    Oct 2002
    Posts
    5,005
    Surely your compiler tells you no.
    Code:
                     DLListNode();
                     DLListNode(const T&)
    7. It is easier to write an incorrect program than understand a correct one.
    40. There are two ways to write error-free programs; only the third one works.*

  7. #7
    Registered User
    Join Date
    Mar 2007
    Posts
    109
    besides that

  8. #8
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    You should try and compile your code before asking questions on whether your code is correct.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  9. #9
    Registered User
    Join Date
    Mar 2007
    Posts
    109
    this is not compiled, i'm answering it from a review book written on paper thats y i am asking, normally i would just compile and see

  10. #10
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    this is not compiled, i'm answering it from a review book written on paper thats y i am asking, normally i would just compile and see
    Type it into your editor, then compile and try it out. Alternatively, look at the answers provided by the book. If there are no answers, then the author probably expected you to confirm your answers by trying it out anyway.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  11. #11
    Registered User
    Join Date
    Mar 2007
    Posts
    109
    hm ok in that case can u help me get mingw working i still can't get it to work

  12. #12
    Registered User
    Join Date
    Mar 2007
    Posts
    109
    how would i compile just that one file anyway if i don't have a filled out DLListNode.template file?

  13. #13
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Yes, but you should post about your MinGW installation problems. The Tech Board is a good place for that, unless you are just having problems compiling your program, in which case post in this forum with the code that you are trying to compile.

    how would i compile just that one file anyway if i don't have a filled out DLListNode.template file?
    Create it yourself, with stubs for the implementation of your class template. Then you need another source file with the main() function used to test out your class template.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  14. #14
    Just Lurking Dave_Sinkula's Avatar
    Join Date
    Oct 2002
    Posts
    5,005
    Quote Originally Posted by DarkDot View Post
    hm ok in that case can u help me get mingw working i still can't get it to work
    Well, one might recommend posting the actual code, rather that just a snippet that you can't debug.
    Last edited by Dave_Sinkula; 04-15-2007 at 11:38 PM. Reason: D'oh!
    7. It is easier to write an incorrect program than understand a correct one.
    40. There are two ways to write error-free programs; only the third one works.*

  15. #15
    Registered User
    Join Date
    Mar 2007
    Posts
    109
    this is the whole code that i have. i meant just mingw in general working to compile in windows. Also i posted in the tech area

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Help Debugging my AVL tree program.
    By Nextstopearth in forum C Programming
    Replies: 2
    Last Post: 04-04-2009, 01:48 AM
  2. Reverse function for linked list
    By Brigs76 in forum C++ Programming
    Replies: 1
    Last Post: 10-25-2006, 10:01 AM
  3. question about a working linked list
    By cold_dog in forum C++ Programming
    Replies: 23
    Last Post: 09-13-2006, 01:00 AM
  4. Linked list probs
    By mouse163 in forum C++ Programming
    Replies: 5
    Last Post: 02-19-2005, 05:41 PM
  5. singly linked list
    By clarinetster in forum C Programming
    Replies: 2
    Last Post: 08-26-2001, 10:21 PM