Function that stores a number into an integer array?

I'm writing a function that stores a number into an array. If the number is greater that the lowest number in the array then it replaces it. The array size is 10. When the number is stored in the array. The lowest number must then be remove. How do I write this?

Thank You!
You would just need to assign the value of the number to the position in the array. It doesn't actually have to be removed.
Like this:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37

void insertNumber( int array[], int newNumber )
  {
     int index, highIndex;
    int size = 10;

     for ( index = 0 ;
             array[index] <= newNumber && index < size  ;
              index++ )
        {
        
        }
 
     if ( index == size )
       {
          array[index] = newNumber;
       }

    else
      {
          for ( highIndex = size ;
             highIndex > index ;
                          highIndex >= index+1 ;
                              highIndex-- )
           {
         array[highIndex] = array[highIndex-1];
          }
      
            array[index] = newNumber; 
                             
     }

   
   size++;
  }

Last edited on
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25

void InsertNumber(int List[], unsigned int Size, int Number)
{

  //check if size of array is zero, if it is, return
  if(Size == 0 ) return;

   int LowNumber = List[0];   //the lowest number
   int LowNumberIndex = 0;  //the index that its found

   //check for lowest number
  for(int x = 0; x < Size; x++)
  {
     if(List[] < LowNumber)
    {
        LowNumber = List[x];
        LowNumberIndex = x;
     }
   }

   //if the number is lower then the lowest number in the array return.
   if(Number <= LowNumber) return;

   List[LowNumberIndex] = Number;
};

Topic archived. No new replies allowed.