Doubly Linked List Node

This is a discussion on Doubly Linked List Node within the C++ Programming forums, part of the General Programming Boards category; Hey i'm trying to create a header file for a doubly linked list node. So far i have Code: #ifndef ...

  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
    20,962
    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.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    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,006
    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,006
    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
    20,962
    You should try and compile your code before asking questions on whether your code is correct.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    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
    20,962
    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.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    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
    20,962
    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.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    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,006
    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

Page 1 of 2 12 LastLast
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, 04:41 PM
  5. singly linked list
    By clarinetster in forum C Programming
    Replies: 2
    Last Post: 08-26-2001, 10:21 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21