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

I have given you a driver called \"ExamList\" that creates 3 unordered lists. Ma

ID: 3705485 • Letter: I

Question

I have given you a driver called "ExamList" that creates 3 unordered lists. Make no changes to "ExamList". If you have correctly completed Lab 9, you should be able to run "ExamList" to provide the output listed below. append takes a LinkedList as a parameter and appends that LinkedList onto the current LinkedList removeDuplicates removes duplicate elements from the current LinkedList. moveNode(LinkedList) removes the first node from the parameter list and pushes it onto . the front of the current LinkedList

Explanation / Answer

//this program is written in c++ and also used stl

#include <iostream>
#include <list>
#include <iterator>
using namespace std;

class SLL{//class used for list object and function
  
public:

list <int> l;//inbuild list (STL) of c++ used
void showlist();
void appendList(list <int>);
void removeDuplicate();
SLL moveNode(SLL);
};

void SLL::appendList(list <int> lst){//function for append two list
this->l.insert(this->l.end(),lst.begin(), lst.end());

}

SLL SLL::moveNode(SLL lst){//
int ele=lst.l.front();
lst.l.pop_front();
this->l.push_front(ele);
return lst;
}
void SLL::removeDuplicate(){//function to remove dulicate element from list
this->l.sort();
this->l.unique();
}
void SLL::showlist()//function to print list
{
list <int> :: iterator it;
cout<<"list:";
for(it = l.begin(); it != l.end(); ++it)
cout << ' ' << *it;
cout << ' ';
}

int main()
{
SLL l1,l2,l3;//here 3 object initilize
for (int i = 0; i < 5; ++i)
{
l1.l.push_back(i * 2);
l2.l.push_front(i * 3);
}
  
for(int i=0;i<5;++i){
l3.l.push_back(i*2);
}
for(int i=0;i<5;++i){
l3.l.push_back(i*4);
}
l1.showlist();
cout<<" ";
l2.showlist();
cout<<" ";
l1.appendList(l2.l);//append list l2 in l1
cout<<" ";
l1.showlist();
  
cout<<" ";
l3.showlist();
cout<<" ";
l3.removeDuplicate();//remove duplicate element from list
l3.showlist();
cout<<" ";
l3=l1.moveNode(l3);//move node of l3 and insert in into first of l1 returning l3
l1.showlist();
cout<<" ";
l3.showlist();
  
return 0;
}