create linkedlist.h and linklist.cpp file , given the linkedlistMain.cpp file ex
ID: 3810092 • Letter: C
Question
create linkedlist.h and linklist.cpp file , given the linkedlistMain.cpp file
executable sample :
Please enter the input filename (or simply press return to use project4-inputA.tab)
Importing patients from project4-inputA.tab ...
There are no entries in the list to display
Selena is not found in the list
Displaying the single entry in the list:
Selena
Selena is in the list
There are no entries in the list to display
Selena is not found in the list
Displaying all 5 entries in the list:
Bryan
Jackie
Aaron
Elen
Jackson
There are no entries in the list to display
INPUT file
File to read from
V
F Selena
D Selena
A Selena
V
F Selena
D Selena
V
F Selena
D Selena
A Jackson
A Elen
A Aaron
A Jackie
A Bryan
V
D Jackson
D Elen
D Aaron
D Jackie
D Bryan
V
Explanation / Answer
LinkedList.h
..................
struct node
{
int data;
struct node *next;
}*head;
class LinkedList
{
public:
LinkedList();
struct node *create(string name);
void insert(string name);
void remove(string name);
void print(string name);
void printAll();
}
LinkedList.cpp
.................
{
head = NULL;
}
{
struct node *t;
t = new(struct node);
if (t == NULL)
{
cout<<"Memory not allocated "<<endl;
return 0;
}
else
{
t->data = name;
t->next = NULL;
return t;
}
}
{
struct node *t, *p;
t = create(name);
if (head == NULL)
{
head = t;
head->next = NULL;
}
else
{
p = head;
head = temp;
head->next = p;
}
}
{
struct node *pre = NULL, *del = NULL;
if (_head->data == name) {
del = head;
head = del->next;
delete del;
return;
}
pre = head;
del = head->next;
while (del != NULL) {
if (del->data == name) {
pre->next = del->next;
delete del;
break;
}
pre = del;
del = del->next;
}
}
{
bool f = false;
if (head == NULL)
{
cout<<"There are no entries in the list to display"<<endl;
return;
}
cout << "Displaying the single entry in the list: "endl;
cout<< name <<endl;
struct node *t;
t = head;
while (t != NULL)
{
if (t->data == name)
{
f = true;
cout<< name << "is in the List "<<endl;
}
t = t->next;
}
if (!f)
cout<<name<<" is not found in the list"<<endl;
}
{
int count =0;
struct node *t;
if (head == NULL)
{
cout<<"There are no entries in the list to display"<<endl;
return;
}
t = head;
while (temp != NULL)
{
count++;
t = t->next;
}
cout<<"Displaying all" <<count << "the entries in the list: "<<endl;
while (temp != NULL)
{
cout<<t->data<<endl;
t = t->next;
}
cout<<"There are no entries in the list to display"<<endl;
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.