Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

1. Create a simple linked list. (code included) 2. Overload the >> operator as a

ID: 3533033 • Letter: 1

Question

1.     Create a simple linked list. (code included)

2.     Overload the >> operator as a friend function to read a list from the file. (Data in file is not sorted)

3.     Overload the << operator as a friend function to write a list to a file.

4.     Write the original output list to the output file.

5.     Write a member function to sort the list using the algorithm for the Bubble sort. When the sort finishes, the smallest value will be pointed to by head_ptr and the largest at the end of the list.

6.     After sorting the list, write it out with the << operator.

7.     You will have three output files, Bubble.h, Bubble.cpp, and the main program.

Sample Input:

            25 15 45 35 65 55

Sample Output:

            55 65 35 45 15 25   // original data as read in

                                                // adding to head of list

            15 25 35 45 55 65   //after Bubblesort

WHAT I HAVE SO FAR:


//BUBBLE.H FILE

#ifndef BUBBLE_H

#define BUBBLE_H

#include<iostream>

#include <fstream>

#include <cstdlib>

struct nodeType

{

int info;

struct nodeType* link;

};

class Bubble

{

private:

nodeType* headPtr;

int noOfNodes;

public :

Bubble()

{

headPtr=NULL;

}

void insertInLinkedList(int info)

{

if(headPtr==NULL)

{

nodeType* temp=(nodeType*)malloc(sizeof(nodeType));

temp->info=info;

temp->link=NULL;

headPtr=temp;

}

else

{

nodeType* temp=(nodeType*)malloc(sizeof(nodeType));

temp->info=info;

temp->link=headPtr;

headPtr=temp;

}

}

};

//friend istream & operator >> (istream &infile, Bubble & mylist);

// friend ostream & operator <<(ostream & outfile, const Bubble & alist);

//prototypes for list clear and copy

#endif

Explanation / Answer

#include #include #include "myList.h" using namespace std; using namespace A; int main() { // create lists myList list1; // declare stream objects ifstream inData; ofstream outData; // open files inData.open("list1.txt"); outData.open("outlist1.txt"); // test for valid files if (!inData) { cout