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

  • SEARCH
  • Home
  • 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 9245787
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T09:20:35+00:00 2026-06-18T09:20:35+00:00

A[5] has elements {a,b,c,d,e} A[2] becomes empty, what is the the best way to

  • 0

A[5] has elements {a,b,c,d,e}

A[2] becomes empty, what is the the best way to move everything to the right so that they fill up the array partially leaving the empty spaces to the far left. I know how to do it with logic and loops, I was wondering if there are any commands that would do it for me?

  • 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-18T09:20:36+00:00Added an answer on June 18, 2026 at 9:20 am

    A C-style array has no concept of an “empty” element. The element will always have a value. You may decide that some value denotes an empty element but that’s up to you. If your “empty” placeholder value is named empty, you could do something along the lines of:

    auto empty_it = std::find(std::begin(arr), std::end(arr), empty);
    std::rotate(empty_it, empty_it + 1, std::end(arr));
    

    This will move the first empty element to the back of the array.

    You’d be much better off using a std::vector, std::list, or other standard library container. They provide functions for removing elements from the container without you having to care about shifting elements around. For example:

    std::vector<int> v = {0, 1, 2, 3, 4, 5, 6};
    v.erase(v.begin() + 3);
    for (auto& x : v) {
        std::cout << x << " ";
    }
    

    This will print 0 1 2 4 5 6. The 3 has been removed from the container.

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

Sidebar

Related Questions

I have an array thats generated dynamically and it has some empty elements. How
Assume I have classes A1 and A2 and a class B that has elements
My scenario is as follows:(C++) In char a[10], the array a[] has elements (numbers)
I have an int array which has no elements and I'm trying to check
I have an array Items which has 10 elements. I need to remove the
I have a very complicated site built on CSS3 that has html elements 3d-transformed,
I have web page that has a collection of tiled elements as a background.
I want to remove the class attribute from all elements that have an empty
I have a form which has elements in a couple of divs. Based on
my CGPathRef has 5 elements, i want to remove the starting point , and

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.