Our linked list class template allowed insertions and deletions at only the fron
ID: 3547145 • Letter: O
Question
Our linked list class template allowed insertions and deletions at only the front and the back of the linked list. These capabilities were convenient for us when we used private inheritance and composition to produce a stack class template and a queue class template with a minimal amount of code by reusing the list class template. Actually, linked lists can do more than those provided by the textbook. In this assignment we want to have a linked list class template to handle insertions and deletions anywhere in the list.
Create an interface to add anywhere in the list , delete a particular element, repopulate the list and exit the list. The program will populate a 20 elements integer list with random number from 0 ~ 200. The list can expend to more than 100 and shrink to 0 element.
Please document the files properly and zip CISP400V7AD7.cpp, ListNote.h and List.h files into a proper named zip file for an advance assignment.
Your expecting result (see below):
(The list is:
47 120 54 179 17 16 180 123 91 74 179 40 28 148 193 185 66 84 119 130
Please select one from of the following selection or enter -1 to exit:
1. Insert an element to the List.
2. Delete an element from the List.
3. Repopulate the List information
:2
Enter an integer to delete: 47
47 was deleted from the list
(the list is:
20 54 179 17 16 180 123 91 74 179 40 20 148 193 185 66 84 119 130
Please select one from the following selection or enter -1 to exit:
1. Insert an element to the List.
2. Delete an element from the List.
3. Repopulate the List information
:1
Enter the index where you want the new value to appear:
20
Enter the value you want added at this location: 300
Invalid index, no data added to list.
Please select one from of the following selection or enter -1 to exit:
1. Insert an element to the List.
2. Delete an element from the List.
3. Repopulate the List information
:1
Enter the index where you want the new value to appear:
19
Enter the value you want added at this location: 200
The list is:
120 54 179 17 16 180 123 91 74 179 40 28 148 193 185 66 84 119 130 200
Please select one from of the following selection or enter -1 to exit:
4. Insert an element to the List.
5. Delete an element from the List.
6. Repopulate the List information
:1
Enter the index where you want the new value to appear:
21
Enter the value you want added at this location: 300
Invalid index, no data added to list.
Please select one from the following selection or enter -1 to exit:
4. Insert an element to the List.
5. Delete an element from the List.
6. Repopulate the List information
:1
Enter the index where you want the new value to appear:
19
Enter the value you want added at this location: 300
(the list is:
20 54 179 17 16 180 123 91 74 179 40 28 148 193 185 66 84 119 130 300 200
Please select one from of the following selection or enter -1 to exit:
4. Insert an element to the List.
5. Delete an element from the List.
6. Repopulate the List information
:1
Enter the index where you want the new value to appear:
0
Enter the value you want added at this location: 400
The list is:
100 120 54 179 17 16 180 123 91 74 179 40 28 148 193 185 66 84 119 130 300 200
Please select one from of the following selection or enter -1 to exit:
1. Insert an element to the List.
2. Delete an element from the List.
3. Repopulate the List information
Explanation / Answer
This is your CISP400V7AD7.cpp file
#include<iostream>
using namespace std;
int t=0;
struct node
{
int data;
node *link;
}*start,*end,*temp,*ptr,*np,*pre,*cons;
#include "ListNote.h"
#include "List.h"
int main()
{
int info,k,pos,n=0;
start=NULL;
while(k!=-1)
{
cout<<"Please select one from of the following selection or enter -1 to exit: ";
cout<<"1. Insert an element to the List. ";
cout<<"2. Delete an element from the List. ";
cout<<"3. Repopulate the List information ";
cin>>k;
cout<<"List index starts with 0 ";
switch(k)
{
case 1:
{
cout<<"Enter the index where you want the new value to appear: ";
cin>>pos;
cout<<"Enter the value you want added at this location: ";
cin>>info;
np=create(info);
ins(pos,np);
display(start);
break;
}
case 2:
{
cout<<"Enter an integer to delete: ";
cin>>info;
del(info);
display(start);
break;
}
case 3:
{
cout<<"Enter the index where you want to replace the value: ";
cin>>pos;
cout<<"Enter the value you want add at this location: ";
cin>>info;
np=create(info);
rel(pos,np);
display(start);
break;
}
default:
{
cout<<"Enter valid choice";
break;
}
}
}
system("pause");
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.