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

Coding In C+ Lab 3- Arrays Implementing Lists using Arrays What you will learn I

ID: 3746341 • Letter: C

Question



Coding In C+ Lab 3- Arrays Implementing Lists using Arrays What you will learn Implementing arrays Implementing list ADT using templates Running time analysis Coding exercise Implement abstract data type list using arrays. Functionalities desired are as follows: Function Description Decide if you need to use any parameters Especially required if you use dynamic Checks if list is 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 management 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 2 parameter void insertAt (int, elemType) Inserts 2d parameter at position void insertEnd (elemType) void removeAt (int) elemType retreiveAt(int) void replaceAt(int, elemType) void clearList() operator- Inserts object to end of the list Removes object at position Retrieves object at position Replaces object at position with 2 Empties the list Overload the assignment operator Here, elemType is the type of the members of the list. In a given list, all elements are of the same type. You should use template implementation to enable functionality to have lists storing different types of objects dynamically What to turn in A zip file containing the arrayList.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. Report it in a file called report.pdf. Include your sources as references in report.pdf

Explanation / Answer

Here is the code for the given question,

Please comment below for further queries regarding the answer or any modifications needed. Thank you.

#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;
}