Question

7. The code segment given sorts an array. Show how this works on the given array by redrawing the array each time one of the entries changes value. const int Isize·6; // list size int list [lsize]; int j, x; for (int i = !size-1; i > 0; i-) { x = list [i]; ji; for (int k = i-1 ; k >= 0; k-) { if (list [k] > x) f j -k; x = list(k); list [j] list [i] list [i]; = x;
0 0
Add a comment Improve this question Transcribed image text
Answer #1

As per your requirement the below one is solution please follow it

Date ouse se 4- 4 and open-kる uke ら24. and ern

Add a comment
Know the answer?
Add Answer to:
7. The code segment given sorts an array. Show how this works on the given array...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • I'm trying to code a C program so it sorts an array of integer numbers of...

    I'm trying to code a C program so it sorts an array of integer numbers of size n in ascending order. My code is written below but its not working properly, its giving me errors, I think my sort and swap functions aren't done right maybe, please help and fix. It says "undefined reference to "SelectionSort" as an error. But the question asks to not change the PrintArray and Main function. #include <stdio.h> void PrintArray(int size, int array[]) { for...

  • 1. What is the output of the following code segment? int array[] = { 8, 6,...

    1. What is the output of the following code segment? int array[] = { 8, 6, 9, 7, 6, 4, 4, 5, 8, 10 }; System.out.println( "Index Value" ); for ( int i = 0; i < array.length; i++ ) System.out.printf( "%d %d\n", i, array[ i ] ); 2. What is the output of the following code segment? char sentence[] = {'H', 'o', 'w', ' ', 'a', 'r', 'e', ' ', 'y', 'o', 'u' }; String output = "The sentence...

  • Consider the following code segment. ArrayList<String> towns = new ArrayList<String> (); towns.add("Baltimore"); towns.add("Bethesda"); towns.add("Wheaton"); towns.add("Greenbelt"); towns.add("Rockville");...

    Consider the following code segment. ArrayList<String> towns = new ArrayList<String> (); towns.add("Baltimore"); towns.add("Bethesda"); towns.add("Wheaton"); towns.add("Greenbelt"); towns.add("Rockville"); for (int k = 1; k< towns.size(); k ++) System.out.print(towns.get(k) + " "); What is printed as a result of executing the code segment? Baltimore Bethesda Wheaton Greenbelt IndexOutOfBoundsException message Baltimore Bethesda Wheaton Greenbelt Rockville Bethesda Wheaton Greenbelt Rockville Refer to the doSomething method: public static void doSomething (ArrayList list, int i, intj) SomeType temp = list.get(i); list.set(i, list.get()); list.set(j, temp); Which best describes...

  • [5 marks] Using selection sort algorithm to sort the array int array[7]-5, 6, 2, 7, 9,...

    [5 marks] Using selection sort algorithm to sort the array int array[7]-5, 6, 2, 7, 9, 4, 3). Assuming we call the following function using statement selection sort (int array, 7); Please fill the table to show the changes of the array int_array after each iteration. The first column is filled. void selection_sort (int list[], int list_size) for (int i = 0; i < list size - 1; 1++) int current min = list[1]; int current_min_index-i for (int j -...

  • In the blank below, write the contents of array arr after the following code is executed...

    In the blank below, write the contents of array arr after the following code is executed up to the comment indicated in the main procedure below? #include <iostream> #include <algorithm> using namespace std; void do something(int list[], const int size); int main() { const int SIZE(10); int arr[SIZE] = { 5, 8, 1, 7, 3, 9, 4, 6, 10, 2 }; do somethingCarr, SIZE); ** Write the contents of array arr in the space below when execution reaches here. */...

  • The following program sorts the array of numbers entered by the user and prints out the...

    The following program sorts the array of numbers entered by the user and prints out the elements in descending order. It has many errors. Debug the code and show the output. #include <stdio.h> #define N 4 void desc(float *a, float *b) float tp; tp=a; a=b; b=tp; int main() int i, j, ii, mark[N] ; for (ii==0;ii<N;ii++) printf("Enter the %d th element of your array: \n",ii); scanf("%d", mark[ii]); printf("You have entered the following array: \n"); for (ii=0,ii<N,ii++) printf("%d ", mark[ii]); printf("\n...

  • 4. Given the following code, int x = 5, n; do{ n = 0; for (int...

    4. Given the following code, int x = 5, n; do{ n = 0; for (int i = 0; i < x; i++) { n = n + x; System.out.println(n); } while (x > 1); a) What will be the value of x after the code segment is executed? Initial value of x 5 b) What is the output of the code segment? c) Explain how the flow of control moves in the given code segment. When explaining, show how...

  • How can I convert the following C code to MIPS Assembly? +++++++++++++++++++++++++++++++++ MIPS main program ++++++++++++++++++++++++++++++++...

    How can I convert the following C code to MIPS Assembly? +++++++++++++++++++++++++++++++++ MIPS main program ++++++++++++++++++++++++++++++++ .data # Defines variable section of an assembly routine. array: .word x, x, x, x, x, x, x, x, x, x # Define a variable named array as a word (integer) array # with 10 unsorted integer numbers of your own. # After your program has run, the integers in this array # should be sorted. .text # Defines the start of the code...

  • whats the answers How many total integers elements are in an array with 4 rows and...

    whats the answers How many total integers elements are in an array with 4 rows and 7 columns? 07 28 11 What is the resulting array contents, assuming that itemList is an array of size 4 having contents -55, -1, 0, 9? for (i = 0; i < 4; ++i) { itemsList[i] - i; -54,0, 1, 10 O 0, 1, 2, 3 O 1, 2, 3, 4 O-55,-1, 0,9 Given an integer array myVals of size N_SIZE (i.e. int[] myVals...

  • Question One (2 marks): What is the complexity of the given code as a function of the problem size n? Show the (complete) details of your analysis. Note: a [ i] s an array with n elements. for (int i...

    Question One (2 marks): What is the complexity of the given code as a function of the problem size n? Show the (complete) details of your analysis. Note: a [ i] s an array with n elements. for (int i- 0; i < n; i++) if (Math.random) > 0.5) if (i%2-0) Insertionsort (a[i]); else Quicksort (a[i]) else for (int j = 0; j < i; j++) for (int k 0: k 〈 i; k++) o (logn) Question One (2 marks):...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT