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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T01:07:11+00:00 2026-05-17T01:07:11+00:00

I have a question for a c++ lab assignment I have. The task is

  • 0

I have a question for a c++ lab assignment I have. The task is to implement some function for adding values, remove values from an array and so on. I have done most of it now, however I have some problem with the insert function. The assignment requires me to insert float values to this array without using any algorithm to sort it after each insert. I may not use anything from STL either. It will assume that I insert every value in sorted position immediately

So I wonder if someone could give me any clue how this problem can be solved?

EDIT
This assignment I am not going to implement it with linked list. It will be for my next assignement.

I have tried to write a insert function according to your pseudo code. I did not get it correctly though. Here’s the code anyway.

void array_insert(data_t list[], int& space_used, data_t value)
{

   if(space_used == 0)
   {
      list[space_used] = value;    
   }
   else
   {

      for(int i = space_used+1; i >= 0; i--)
      {
         if(value > list[i])
         {
            list[i+1] = value;
            break;
         }
         else
         {
            list[i+1] = list[i];
         }
         if(i == 0)
         {
            list[i] = value;
         }
      }
   }
   space_used++;
}

finally finished, here’s the complete code. Thanks for the help from Mark and Casablanca

  • 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-17T01:07:11+00:00Added an answer on May 17, 2026 at 1:07 am

    You have to shift all elements to make room for the new element. This is an O(n) operation. Since you can’t do better than O(n) I think it is reasonable to use this simple O(n) algorithm:

    • Set i to the index of the last element in the array
    • If the element to insert is larger then a[i] then insert the element at index i+1 and stop.
    • Otherwise set a[i+1] = a[i] then decrease i and repeat the previous step.
    • If i reaches 0, insert the element at the start.

    This assumes that your array has space to insert an extra element.

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

Sidebar

Related Questions

I have some trouble regarding my lab assignment: When my program tries to prompt
I have question. I have some app on facebook and getting this error Fatal
I have question about XSLT1.0. The task is to write out in HTML all
I have question regarding the use of function parameters. In the past I have
I have question concerning a function I created. I would like to show the
I have question related to what is done in SMS application is if i'm
my robotics lab is looking for programmers to work on some projects we have
I have question about sending emails from MVC3 application. I already read for exmple
I have question about how I can save the result of function I have
I have a question regarding the online Google cloud lab @ http://code.google.com/apis/sql/docs/developers_guide_java.html at the

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.