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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T20:49:53+00:00 2026-05-12T20:49:53+00:00

Im wondering why my data in ‘intFront’ does not stay the same. Im shifting

  • 0

Im wondering why my data in ‘intFront’ does not stay the same. Im shifting the elements in my array left:

void stack::rotate(int nRotations)
{
    for (; nRotations > 0 ;) // Number of Rotations to the left
    {
        intFront = &items[top+1].n; 
        for ( int shiftL = 0; shiftL < count-1; shiftL++ )
        {
            items[shiftL] = items[shiftL+1]; // shift left from the front
        }    
        items[count-1].n = *intFront;
        nRotations--; // decrement=0 will indicate no more rotations left
    }
}

Whats happening is that the first value or “head” or “front” of the array is put into a varaible ‘intFront’. I rotate everything left by the given number of rotations, hoping to just make a simple transfer at the end. Guess not..

  • 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-12T20:49:53+00:00Added an answer on May 12, 2026 at 8:49 pm
    1. You overrun your array: read of items[shiftL+1] goes beyond array bounds at last iteration,
    2. You save a pointer to member of a structure into intFront and then override these structures by value in the inner loop – that’ll sure change value intFront points to,
    3. There’s no need for doing multiple copies, i.e. no need for two embedded loops, since you know by how much you need to shift (nRotations).
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm wondering why all frameworks pass data to Views by an array, usually called
I am wondering if the data posted to the server is same when using
I was just wondering how does data loads for Twitter and Facebook apps.. Like
I was wondering if its possible to pass data stored in a javascript array
i've been wondering why my variable is not saving data. this is my code
I was wondering if data types in a a literal create table statement, executed
I was wondering if I could send some data from my client-side (2d application
I'm wondering what kind(s) of data structures / algorithms might help facilitate handling the
I was wondering how you can recover data from your logfile. I'm using sql
I was wondering about some best practices for data binding in web forms. For

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.