Question: 1. Use step count method and analyze the time complexity Code: sorted_disks sort_lawnmower(const disk_state& before) { assert(before.is_alternating()); disk_state temp = before; int count = 0;

1. Use step count method and analyze the time complexity

Code:

sorted_disks sort_lawnmower(const disk_state& before) {

assert(before.is_alternating());

disk_state temp = before;

int count = 0;

while(!temp.is_sorted())

{

for(size_t i = 0; i

{

if(temp.get(i) > temp.get(i+1))

{

temp.swap(i);

count++;

}

}

for(size_t i = (temp.total_count() -1); i > 0 ; i--)

{

if(temp.get(i)

{ temp.swap(i-1);

count++;

}

}

}

return sorted_disks(disk_state(temp), count);

}

1. Use step count method and analyze the time complexity Code: sorted_disks

sorted_disks sort_lawnmower(const disk_state& before) { // check that the input is in alternating format assert(before.is_alternating()); disk_state temp = before; int count = 0; while( ! temp.is_sorted()) { for(size_t i = 0; i temp.get(i+1)) { temp. swap(i); count++; for(size_t i = (temp.total_count() -1); i >0; i--) { if(temp.get(i)

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!