daily pastebin goal
26%
SHARE
TWEET

CS286 HW 2

a guest Jan 18th, 2018 60 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // Don’t generate any MIPS for the next 4 lines
  2. #include <iostream>
  3. #include <cstdlib> using namespace std;
  4. void shift( int array[], int index );
  5. // start creating MIPS code for the rest.
  6. // Note that some lines are commented (no code for those)
  7. int main(){
  8.     int array[1000];
  9.     int x;
  10.     for( int i = 0; i < 1000; i++ ){
  11.         array[i] = 2001;
  12.     }
  13.  
  14. // for ( int i = 0; i < 1000; i++ ) cout << array[i] << " "; // cout << "----"<<endl;
  15. // Assume function rand() is implemented at memory address RAND
  16. // and it returns a random integer in register $v0
  17.  
  18.     for( int i = 0; i < 1000; i++){
  19.         x = rand()%2000;
  20.         for( int j = 0;j < 1000; j++ ){
  21.             if( x < array[j] ){
  22.                 shift( array, j);
  23.                 array[j] = x;
  24.                 j = 1000;
  25.             }
  26.         }
  27.     }
  28. // for ( int i = 0; i < 1000; i++ ) cout << array[i] << " ";
  29. // cout << "----"<<endl;
  30.  
  31. }
  32.  
  33. void shift( int array[], int index ){
  34.     for (int i = 999; i > index; i-- )
  35.         array[i] = array[ i-1 ];
  36. }
RAW Paste Data
Top