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:
 ``12345678910111213141516171819202122232425262728293031323334353637`` `````` 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
 ``12345678910111213141516171819202122232425`` `````` 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.