Question

In: Computer Science

Please finish this code and make it work. This is my homework and my professor wont...

Please finish this code and make it work. This is my homework and my professor wont allow me to change the code in main, it's a set of huge numbers need to sort by radixsort with bit operation.

#include <iostream>

using namespace std;

void radixLSD_help(int *items, int length, int bit)

{

  

// – Count number of items for each bucket.

  

// – Figure out where each bucket should be stored (positions

// of the first and last element of the bucket in the scratch

// array).

// – Copy each item to the corresponding bucket (in the scratch

// array).

// – Copy the scratch array back into items.

}

void radixLSD(int *items, int length)

{

int bit_per_item = sizeof(int) * 8;

  

int bit;

  

for (bit = 0; bit < bit_per_item; bit++)

{

radixLSD_help(items, length, bit);

cout << "Done with bit " << bit;

}

}

void sort(int *A,int n)

{

radixLSD(A, n);

}

void sort( int *A, int n);

int main()

{

int i, offset, j;

int B[10000000];

time_t t;

srand( (unsigned) time( &t ));

offset = rand()%10000000;

for( i = 0; i< 10000000; i++ )

{

B[i] = ((91*i)%10000000) + offset;

}

printf("Prepared array of 10 million integers; calling sort\n");

sort( B[], 10000000 );

printf("finished sort, now check result\n");

for( i=0, j=0; i < 10000000; i++ )

if( B[i] != i+ offset ) j++;

if( j == 0 )

printf("Passed Test\n");

else

printf("Failed Test. %d numbers wrong.\n", j );

}

Solutions

Expert Solution

Updated and working code:

#include <iostream>

using namespace std;

void radixLSD_help(int *items, int length, int bit)

{

  

// – Count number of items for each bucket.

  

// – Figure out where each bucket should be stored (positions

// of the first and last element of the bucket in the scratch

// array).

// – Copy each item to the corresponding bucket (in the scratch

// array).

// – Copy the scratch array back into items.

}

void radixLSD(int *items, int length)

{

int bit_per_item = sizeof(int) * 8;

  

int bit;

  

for (bit = 0; bit < bit_per_item; bit++)

{

radixLSD_help(items, length, bit);

cout << "Done with bit \n" << bit;

}

}

void sort(int *A,int n)

{

radixLSD(A, n);

}

void sort( int *A, int n);

int main()

{

int i, offset, j;

int B[10000000];

time_t t;

srand( (unsigned) time( &t ));

offset = rand()%10000000;

for( i = 0; i< 10000000; i++ )

{

B[i] = ((91*i)%10000000) + offset;

}

printf("Prepared array of 10 million integers; calling sort\n");

sort( B, 10000000 );

printf("finished sort, now check result\n");

for( i=0, j=0; i < 10000000; i++ )

if( B[i] != i+ offset ) j++;

if( j == 0 )

printf("Passed Test\n");

else

printf("Failed Test. %d numbers wrong.\n", j );

}


Related Solutions

I have to finish the code given by my diff eq professor to analyze the lorenz...
I have to finish the code given by my diff eq professor to analyze the lorenz function at different initial conditions and different values for p. I am not sure how to input the lorenz function in the way the code is set up. Here is the code provided for matlab: function lorenz s = 10; b = 8/3; p = 0.15; y = @(t,x) [ ; ; ]; % you are responsible for entering the lorenz system here T...
Show work please, this is the last problem for my homework and I cannot figure this...
Show work please, this is the last problem for my homework and I cannot figure this out for the life of me An IP4 datagram arrived with the following information in the header (in hexadecimal):                0x4A 00 00 56 00 03 58 50 18 06 58 50 7C 4E 03 02 B4 0E OF 15 2f………. Are there any options? How many bytes, if any? How many more routers can the packet travel to? Explain. What is the size...
this is my matlab code for class, my professor commented "why is the eps an input...
this is my matlab code for class, my professor commented "why is the eps an input when it is set inside the function and not specified as a variable? how do i fix? function[] = () %Declare Global Variables global KS; global KC; KC = 0; KS = 0; End = 0; while (End == 0) choice = questdlg('Choose a function', ... 'Fuction Menu', ... 'A','B','B'); switch choice; case 'A' Program = 'Start'; while strcmp(Program,'Start'); Choice = menu('Enter the Trigonometric...
I already finish the argumentative topic about abortion, but my professor does not want me to...
I already finish the argumentative topic about abortion, but my professor does not want me to write about it. Can someone help me write 500 words about this argumentation "Education should be free for everyone".
PLEASE WORK THE PROBLEM STEP BY STEP. MY PROFESSOR IS A VERY HARD GRADER ALWAYS WANT...
PLEASE WORK THE PROBLEM STEP BY STEP. MY PROFESSOR IS A VERY HARD GRADER ALWAYS WANT STUDENT SHOW WORK. Sanders Corporation operates a factory in Arizona. Due to a change in business climate an impairment test is deemed appropriate. Management has acquired the following information: Cost $243,000,000 Accumulated depreciation 112,000,000 Estimate of the total undiscounted future cash flows 110,000,000 Present value of estimated future cash flows 94,000,000 Estimated fair value of the Arizona factory, as appraised 90,000,000 Required: a) Determine...
Please make my Code working and pass the test but do NOT change anything in main...
Please make my Code working and pass the test but do NOT change anything in main function, thank you. #include <iostream> using namespace std; void sort(int *A, int n){    for(int passes = 0;passes < 2;passes++) { // shift can have only two values either 0 or 16, used for shifting purpose int shift = passes * 16; int N = 1<<(16 + 1);    // Temporary array for storing frequency of upper or lower 16 bits int temp[N];   ...
Please add to this Python, Guess My Number Program. Add code to the program to make...
Please add to this Python, Guess My Number Program. Add code to the program to make it ask the user for his/her name and then greet that user by their name. Please add code comments throughout the rest of the program If possible or where you add in the code to make it ask the name and greet them before the program begins. import random def menu(): print("\n\n1. You guess the number\n2. You type a number and see if the...
I have a project to make and my professor wants me to make a Synopsis. She...
I have a project to make and my professor wants me to make a Synopsis. She wants me to put together a synopsis of the SBA grant EIDL loan program and payroll protection program. The criteria that the small businesses have to meet, what potential benefit would these small businesses receive and so on and so forth. What is the best format for this Synopsis? Thank you.
please make sure it's in your own words, NOT copied from Google, my professor would know...
please make sure it's in your own words, NOT copied from Google, my professor would know and it MUST be typesetting 6) List 2 types of utility software and what each one does. 7) Explain what is malicious software and what it does 8) Explain what is antivirus software and what it does 9) Thoroughly explain the unique functions and usage of the following operating systems: (20 points) Do not copy & paste. Explain in your own words. a. Windows...
Please make sure it's in your own words NOT copied from Google, my professor would know....
Please make sure it's in your own words NOT copied from Google, my professor would know. and it MUST be typewriting. 1) Explain system software and what it does. 2) List 2 types of system software and what each one does. 3) Explain application software and what it does. 4) List 2 types of application software and what each one does. 5) Explain utility software and what it does.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT