Question: Using the code from here (I have modified it and removed the menu) prepare a new .cpp program which will do the following: 1. Create

Using the code from here (I have modified it and removed the menu) prepare a new .cpp program which will do the following:

1. Create a list of the following elements [11,10,9,8,7,6,5,4,3,2,1] using obj.Insert

2. Delete element #5 (counting from 0) using obj.Delete

3. Insert element 100 at position 8 (counting from 0) using obj.Insert

4. Modify the Output function to save the list to a file. The name of the file is provided as an argument.

- obj.Output('test.txt');

5. Using new obj.Output save the resulted list to a file with the following name. FirstName.LastName.aList.txt. For example. Serghei.Mangul.aList.txt

5. Create a new class for the linked list. The new class should have the following functions:

- Delete, Insert and Output

6. Using object from the linked list repeat steps 1-5. For step 5 the name of the file should be FirstName.LastName.lList.txt

provided code:

#include
using namespace std;
template
class LinearList
{
private:
int length;
int MaxSize;
T *element;
public:
LinearList(int MaxLinearSize=10);
~LinearList(){delete[]element;}
int isEmpty()const{return length==0;}
int Length()const{return length;}
int Find(int k,T&x)const;
int Search(const T&x)const;
void Delete(int k,T&x);
void Insert(int k,const T&x);
void Output()const;
};
template
LinearList::LinearList(int MaxListSize)
{
MaxSize=MaxListSize;
element=new T[MaxSize];
length=0;
}
template
int LinearList::Find(int k,T&x)const
{
if(k<1||k>length)
return 0;
x=element[k-1];
return 1;
}
template
int LinearList::Search(const T&x)const
{
for(int i=0;i
if(element[i]==x)
return ++i;
return 0;
}
template
void LinearList::Delete(int k,T&x)
{
if(Find(k,x))
{
for(int i=k;i
element[i-1]=element[i];
length--;
}
else
cout<<"out of bounds ";
}
template
void LinearList::Insert(int k,const T&x)
{
if(k<0||k>length)
cout<<"out of bounds ";
if(length==MaxSize)
cout<<"no memory ";
for(int i=length-1;i>=k;i--)
element[i+1]=element[i];
element[k]=x;
length++;
}
template
void LinearList::Output()const
{
if(isEmpty())
cout<<"list is empty ";
else
for(int i=0;i
cout<
}
void menu()
{
cout<<" MENU " ;
cout<<"----------- ";
cout<<"1.Length ";
cout<<"2.Find ";
cout<<"3.Search ";
cout<<"4.Delete ";
cout<<"5.Insert ";
cout<<"6.Output ";
cout<<"------------- ";
}
int main()
{
int ch;
int k,x,len,p;
LinearList obj;
obj.Insert(0,10);
obj.Insert(1,7);
obj.Insert(2,5);
obj.Output();
cout<
int temp=7;
obj.Delete(1,temp);
obj.Output();
cout<
obj.Insert(1,21);
obj.Output();
cout<
return 0;
}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!