Coding in C++ Use main.cpp and linkedListList.h Implementing Lists using Linked
ID: 3750883 • Letter: C
Question
Coding in C++ Use main.cpp and linkedListList.h Implementing Lists using Linked Lists What you will learn Implementing linked lists The list ADT .Templates . Running time analysis Coding exercise Extend the example discussed in class to implement list functionalities using linked lists in a template called linkedListList. Functionalities desired are as follows: Function Constructors Destructors bool isEmpty() const bool isFull) const int listsize() const int maxListSize() const void print() bool isItemAtEqual (int, elemType) Checks if the item at position matches the 2n parameter void insertAt (int, elemType) void insertEnd(elemType) void removeAt (int) elemType retreiveAt(int) void replaceAt (int, elemType) void clearList operator Description Checks if list is emp Checks if list is full Returns the size of the list Returns the maximum possible size of the list Prints the elements of the list on the console Inserts 2nd parameter at position Inserts object to end of the list Removes object at position Retrieves object at position Replaces object at position with 2d parameter Empties the list Overload the assignment operator What to turn in A zip file containing the linkedListlist.h file with your template declaration and implementation, and a main.cpp file with test cases to show that your program works. For each function, analyze the running time of your algorithm, i.e.,the time complexity of your algorithms in big-O notation. Report it in a file called report.pdf. Include your sources as references in report.pdfExplanation / Answer
ANSWER :
#include<iostream>
using namespace std;
#include<conio.h>
template<class T>
class Nodes
{
public:
T info;
Nodes<T> *Links;
};
template<class T>
class list
{
private:
Nodes<T> *start;
public:
list();
~list();
void create_List();
void del();
void insert();
void view();
};
template<class T>
list<T>::list()
{
start=NULL;
}
template<class T>
list<T>::~list()
{
Nodes<T> *next;
while(start)
{
next=start->Links;
delete start;
start=next;
}
}
template<class T>
void list<T>::create_List()
{
T a;
Nodes<T> *current,*pointerr;
cout<<" Enter info Of New Node (Enter 0 To Have other options):";
cin>>a;
while(a)
{
current=new Nodes<T>;
current->info=a;
current->Links=NULL;
if(start==NULL)
start=current;
else
pointerr->Links=current;
pointerr=current;
cout<<" Enter info Of New Node (Enter 0 To Have other options):";
cin>>a;
}
}
template<class T>
void list<T>::insert()
{
Nodes<T> *current,*pointerr;
T ele;
char ch;
pointerr=start;
current=new Nodes<T>;
cout<<" Enter info Of New Node:";
cin>>current->info;
current->Links=NULL;
cout<<" Do u wish to insert at the start [y/n]:";
cin>>ch;
if(ch=='Y'||ch=='y')
{
current->Links=start;
start=current;
}
else
{
cout<<" Specify after which element do u want to insert :";
cin>>ele;
while(pointerr!=NULL)
{
if(pointerr->info==ele)
{
current->Links=pointerr->Links;
pointerr->Links=current;
break;
}
else
{
pointerr=pointerr->Links;
}
}
}
}
template<class T>
void list<T>::del()
{
T ele;
char choice;
Nodes<T> *pointerr,*ptr1;
if(start==NULL)
{
cout<<" Sorry list is empty.";
}
else
{
pointerr=start;
cout<<" Do u want to delete start element? [y/n]:";
cin>>choice;
if(choice=='y'||choice=='Y')
{
start=start->Links;
delete pointerr;
}
else
{
cout<<" Specify which element do u want to delete :";
cin>>ele;
while(pointerr!=NULL)
{
if(pointerr->Links->info==ele)
{
ptr1=pointerr->Links;
pointerr->Links=ptr1->Links;
delete ptr1;
return;
}
else
{
pointerr=pointerr->Links;
}
}
}
}
}
template<class T>
void list<T>::view()
{
Nodes<T> *pointerr;
if(start==NULL)
{
cout<<" Sorry list is empty..";
}
else
{
pointerr=start;
while(pointerr!=NULL)
{
cout<<pointerr->info<<" ";
pointerr=pointerr->Links;
}
}
}
int main()
{
int n;
list <int> l;
l.create_List();
do
{
cout<<" 1.Insertion 2.Deletion 3.Print List 4.Exit ";
cout<<" Enter your option : ";
cin>>n;
switch(n)
{
case 1: l.insert();
break;
case 2: l.del();
break;
case 3: l.view();
break;
case 4:
exit(0);
break;
}
}while(n<=4);
_getch();
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.