Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

chmod: WARNING: can't access prog.cpp chmod: WARNING: can't access ans.cpp //------------------------------------------------------------------------ // Directions: COMPLETE the code to implement bubble sort on a linked list: //

chmod: WARNING: can't access prog.cpp

chmod: WARNING: can't access ans.cpp

//------------------------------------------------------------------------

// Directions: COMPLETE the code to implement bubble sort on a linked list:

// (1) Complete the SwapValue function

// (2) Complete the for loop in function LL_BubbleSort

// (3) Complete in inner while loop in function LL_BubbleSort.

// (4) Call LL_BubbleSort in main.

//------------------------------------------------------------------------

#include

#include

using namespace std;

struct NODE{int val; NODE * next; NODE(int v, NODE * n){val=v; next=n;}};

void Show(NODE * H)

{

NODE * p = H;

while (p != NULL) {cout << ' ' << p->val; p = p->next;}

}

void SwapValue (NODE * x, NODE * y)

{

//-| (1)

}

void LL_BubbleSort (NODE * H)

{

int pass=1, listsize=0;;

NODE * p, * q = NULL, * prev = NULL;

//-| Determine SIZE of list.

p = H;

while (p != NULL) { listsize++; p = p-> next;}

if (listsize <= 1) return;

//-| (2)

for (pass=1; ; )

{

prev = H;

q = H->next;

while ( q != NULL)

{

//-| (3)

prev = q;

q = q->next;

}//q-loop

}//p-loop

}//LL_Bubblesort

int main()

{

int n, A[]={1,2,6,8,5,7,9,5,9,4,15};

NODE * LIST = NULL;

cin >> n;

for (int k=1; k<=n; k++)

LIST = new NODE(A[k-1], LIST);

cout << endl << "BEFORE: "; Show(LIST); // DO NOT BOTHER!!

//-| (4)

cout << endl << "AFTER: "; Show(LIST); // DO NOT BOTHER!!

cout << endl; return 0; // DO NOT BOTHER!!

}

==============

==> (1) File 'prog.cpp' has been placed in the testing directory.

==> (2) Work in a different window, in the testing directory

==> (3) Edit, compile and test the code in file prog.cpp.

==============

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

Step: 3

blur-text-image

Ace Your Homework with AI

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

Get Started

Students also viewed these Databases questions