Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Please do the PARTITION part only following the below-mentioned conditions, do run the entire code in your IDE to make sure it runs perfectly

Please do the "PARTITION" part only following the below-mentioned conditions, do run the entire code in your IDE to make sure it runs perfectly and please only upload the code snippet that needs to be added, thank you!

.text # test quicksort with smallTable la $a0, smallTable li $a1, 0 li $a2, 6 jal qs # terminate li $v0, 10 syscall #void quicksort (int v[], int start, int end){ # if (start < end){ # int q = partition(v, start, end); # quicksort(v, start, q - 1); # quicksort(v,q + 1,end); # } #} # arguments: $a0 = v[], $a1 = start, $a2 = end # saved variables: $s0 = q, $s1 = v[], $s2 = start, $s3 = end qs: addi $sp,$sp, -20 sw $ra, 16($sp) sw $s3,12($sp) # save $s3 on stack sw $s2, 8($sp) # save $s2 on stack sw $s1, 4($sp) # save $s1 on stack sw $s0, 0($sp) # save $s0 on stack ################################################### # YOUR CODE HERE slt $t0, $a1, $a2 beq $t0, $zero, done # if start >= end, return # call partition with v[], start, end move $s1, $a0 move $s2, $a1 move $s3, $a2 jal partition # save partition result in $s0 move $s0, $v0 # quicksort for the left side of pivot addi $a2, $s0, -1 jal qs # quicksort for the right side of pivot addi $a1, $s0, 1 move $a2, $s3 jal qs ################################################### done: lw $s0, 0($sp) # restore $s0 from stack lw $s1, 4($sp) # restore $s1 from stack lw $s2, 8($sp) # restore $s2 from stack lw $s3,12($sp) # restore $s3 from stack lw $ra,16($sp) # restore $ra from stack addi $sp,$sp, 20 # restore stack pointer jr $ra #int partition (int v[], int start, int end){ # int pivot = v[end]; # int i = start; # for (int j = start; j < end; j++ ){ # if (v[j] <= pivot){ # swap(v,i,j); # i++; # } # } # swap(v, i, end); # return i; #} # arguments: $a0 for v[], $a1 = start, $a2 = end # saved values: $s0 for pivot, $s1 for i, $s2 for j, $s3 for v[], $s4 for start, $s5 for end # return value: $v0 for return i partition: addi $sp,$sp, -28 sw $ra, 24($sp) sw $s5, 20($sp) sw $s4, 16($sp) sw $s3,12($sp) # save $s3 on stack sw $s2, 8($sp) # save $s2 on stack sw $s1, 4($sp) # save $s1 on stack sw $s0, 0($sp) # save $s0 on stack ################################################### # YOUR CODE HERE ################################################### lw $s0, 0($sp) # restore $s0 from stack lw $s1, 4($sp) # restore $s1 from stack lw $s2, 8($sp) # restore $s2 from stack lw $s3,12($sp) # restore $s3 from stack lw $s4,16($sp) lw $s5,20($sp) lw $ra,24($sp) # restore $ra from stack addi $sp,$sp, 28 # restore stack pointer jr $ra # swap procedure: $a0 is address of array, $a1 is k, $a2 is j swap: ################################################### # YOUR CODE HERE sll $t0, $a1, 2 #t0 = 4i add $t0, $t0, $a0 #t0 = v + 4i lw $t1, 0($t0) #t1 = v[i] sll $t2, $a2, 2 #t2 = 4j add $t2, $t2, $a0 #t2 = v + 4j lw $t3, 0($t2) #t3 = v[j] sw $t3, 0($t0) #v[i] = v[j] sw $t1, 0($t2) #v[j] = v[i] jr $ra ################################################### 

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Conceptual Database Design An Entity Relationship Approach

Authors: Carol Batini, Stefano Ceri, Shamkant B. Navathe

1st Edition

0805302441, 978-0805302448

More Books

Students also viewed these Databases questions

Question

What are the main ways to deliver strategy?

Answered: 1 week ago