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 9110021
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T03:10:43+00:00 2026-06-17T03:10:43+00:00

I have a set of arrays, with each array ( data[] ) stored in

  • 0

I have a set of arrays, with each array (data[]) stored in a doubly linked list node ArrayNode. I start at some given index in an array, and I iterate to another index in another array (they may be the same array). I know for sure that my two nodes are linked, and that the first is “to the left” of the second.

struct ArrayNode
{
 ArrayNode* prev;
 ArrayNode* next;

 int data[16];
 unsigned int count;
};



void iterate(ArrayNode* startnode, unsigned int startposition, ArrayNode* endnode, unsigned int endposition)
{
 for (unsigned int index = startposition; index < startnode->count; ++index)
 {
  std::cout << startnode->data[index] << "\n"; //I'd do some processing here
 }

 for (ArrayNode* node = startnode->next; node != endnode; node = node->next)
 {
  for (unsigned int index = 0; index < node->count; ++index)
  {
   std::cout << node->data[index] << "\n"; //I'd do some processing here
  }
 }

 for (unsigned int index = 0; index < endposition; ++index)
 {
  std::cout << endnode->data[index] << "\n"; //I'd do some processing here
 }
}

The above code is flawed in a couple ways. First of all, if startnode == endnode, it will give the incorrect output. Second, having 3 loops is inefficient for maintenance and code size. It seems like it should be possible to have the middle nested loop handle all cases elegantly, but I’m not seeing how. Is it? If not, how should this be done?

I want to avoid making an iterator object for this if possible.

  • 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-06-17T03:10:44+00:00Added an answer on June 17, 2026 at 3:10 am

    This should work:

    void iterate(ArrayNode* startnode, unsigned int startposition, ArrayNode* endnode, unsigned int endposition)
    {
      ArrayNode* node = startnode;
      unisgned int pos = startposition;
      while (!(node == endnode && pos == endposition)) {
        process(node->data[pos]);
        ++pos;
        if (pos == node->count) {
          pos = 0;
          node = node->next;
        }
      }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a multidimensional array of bools, with each element set to true: var
I have an array set inside a velocity template that contains some paths. The
I have a process which is repeated on a set of data stored in
Trying to learn about php's arrays today. I have a set of arrays like
I have set an array in my config file that I use global in
I have set the form decorators in this way: <?php $this->setElementDecorators(array( 'Label', array(array('labelTd' =>
I have a set of ids and names in an associative array and in
I have a set of values that I'm pushing into an array in the
I have an app set up where I convert an NSString into an array
I have an array which contains a set of UIImage in byte forms. --My

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.