Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6961835
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T15:34:55+00:00 2026-05-27T15:34:55+00:00

I wrote the following code when trying to make a doubly-linked list with an

  • 0

I wrote the following code when trying to make a doubly-linked list with an internal STL-like iterator. I’ll just provide the header file with the non-relevant parts trimmed out for now.

My questions are…

  1. The STL uses iterators in a certain way – specifically, you navigate over an STL container from the .begin() iterator up to but not including the .end() iterator. To do this the .end() iterator has to be one-past the end of the container. How would I implement this kind of semantic given what I’ve started with (this is the main question)?

  2. Is there anything missing in the interface as it stands (with regard to the iterator class and things that should be present in it)?

Here’s the code:

template <typename T>
class Node
{
    T data;
    Node<T>* next;
    Node<T>* prev;
};

template <typename T>
class LinkedList
{
    public:

        class Iterator
        {
            public:

                Iterator() {}
                explicit Iterator(const Node<T>& init) { current = init; }

                //Dereference operator - return the current node's data.
                inline T& operator*() { return current->data; }

                //Prefix returns by reference.
                inline Iterator& operator++()   { current = current->next; return *this; } 
                inline Iterator& operator--()   { current = current->prev; return *this; }

                //Postfix returns non-reference and has int parameter to differentiate function signature.
                inline Iterator operator++(int) { Iterator res = *this; current = current->next; return res; }
                inline Iterator operator--(int) { Iterator res = *this; current = current->prev; return res; }

            private:

                Node<T>* current;
        };

        Iterator begin() { return Iterator(m_start); }
        Iterator end()   { return Iterator(m_end);   }

    private:
        Node<T>* m_start;
        Node<T>* m_end;
};

I’m aware that I may or may not have problems with the ++/– operators, but that doesn’t particularly bother me as I’ll work those out when I have enough code to do some testing on this. Feel free to drop hints though if you’re inclined 🙂

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T15:34:56+00:00Added an answer on May 27, 2026 at 3:34 pm
    1. First node’s prev pointer is NULL, so is last node’s next pointer. One-past-the-end’s current pointer would be NULL.

    2. operator->

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i wrote following code to create a linkbutton programmatically, but its showing like lable
I wrote following code...but i am getting Error like: Error 1 'LoginDLL.Class1.Login(string, string, string)':
I'm trying to make an implementation of a double linked list which connects to
I am trying to use the following code to write data into an excel
I'm trying to write a piece of code that will do the following: Take
if wrote the following code and do not understand why the trace returns false:
I wrote the following code: import java.lang.*; import DB.*; private Boolean validateInvoice(String i) {
In C++Builder, I wrote the following code (in Button1Click handler), When I run in
I'm working with the jQuery Validation plugin and I wrote the following code which
I needed some simple string encryption, so I wrote the following code (with a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.