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

Please use Link List & C++ wnloads/HW3.pdf Homework 3 Due October 10th, 2018 You

ID: 3756239 • Letter: P

Question

Please use Link List & C++

wnloads/HW3.pdf Homework 3 Due October 10th, 2018 You will need to submit a written report with part of your codes and your source code via Blackboard. You also need to bring in a hard copy of the report with part of your codes to the class on the day that this is due. Name your header file as LastName(3 to 5 letters) FirstNameInitial HW3.h and your implementation file as LastName(3 to 5 letters) FirstNamelnitial HW3.cpp Note: You can only use iostream, cassert, cctype, cmath, cstdio, and cstdlib. 1. Create a class Node a. Create a Node with data, i.e. constructor b. The basic class Node functions, i.e. set, get, link). etc. 2. Create a singly linked list. Create class/functions that a. Insert a Node in the front b. Delete first Node c. Insert Node at the end d. Delete last Node e. Return the size of the list f. Delete all Node g. Print all Node h. Insert a Node at position i i. Delete a Node at position i Overload your insert functions so it can directly insert data k. Get the Node at position i, i.e. locate 1. Get the Node with target data, i.e. search m. Check if there a cycle n. Swap two Node at position i and i+1, change the link and not the data o. Swap two Node at position i and j, change the link and not the data p. Reverse the whole list q. (Extra Credit) Sort without creating a new list Your report should consist of, but not limited to: .Briefly explain what this function does . Briefly explain how this function works, if applicable . Pre- and Post-condition, if applicable . Worst case time complexity Example structures of the report I. An overview of this homework 2. Code for question I 3. Explanation of question 1 4. Code for question2 5. Explanation of question 2

Explanation / Answer

#include<iostream>
#include<conio.h>
#include<stdlib.h>
using namespace std;
class Node
{
public:
int dataa;
Node* nxtt;
};
class List:public Node
{

Node *f,*l;
public:
List()
{
f=NULL;
l=NULL;
}
void create();
void insert();
void delet();
void display();
void search();
};
void List::create()
{
Node *tmp;
tmp=new Node;
int n;
cout<<" Enter an Element:";
cin>>n;
tmp->dataa=n;
tmp->nxtt=NULL;
if(f==NULL)
{
f=tmp;
l=f;
}

else
{
l->nxtt=tmp;
l=tmp;
}
}
void List::insert()
{
Node *pre,*curr;
pre=NULL;
curr=f;
int countr=1,posi,choice,n;
Node *tmp=new Node;
cout<<" Enter an Element:";
cin>>n;
tmp->dataa=n;
tmp->nxtt=NULL;
cout<<" INSERT AS 1:FIRSTNODE 2:LASTNODE 3:IN BETWEEN FIRST&LAST NODES";
cout<<" Enter Your Choice:";
cin>>choice;
switch(choice)
{
case 1:
tmp->nxtt=f;
f=tmp;
break;
case 2:
l->nxtt=tmp;
l=tmp;
break;
case 3:
cout<<" Enter the Position to Insert:";
cin>>posi;
while(countr!=posi)
{
pre=curr;
curr=curr->nxtt;
countr++;
}
if(countr==posi)
{
pre->nxtt=tmp;
tmp->nxtt=curr;
}
else
cout<<" Not Able to Insert";
break;

}
}
void List::delet()
{
Node *pre=NULL,*curr=f;
int countr=1,posi,choice;
cout<<" DELETE 1:FIRSTNODE 2:LASTNODE 3:IN BETWEEN FIRST&LAST NODES";
cout<<" Enter Your Choice:";
cin>>choice;
switch(choice)
{
case 1:
if(f!=NULL)
{
cout<<" Deleted Element is "<<f->dataa;
f=f->nxtt;
}
else
cout<<" Not Able to Delete";
break;
case 2:
while(curr!=l)
{
pre=curr;
curr=curr->nxtt;
}
if(curr==l)
{
cout<<" Deleted Element is: "<<curr->dataa;
pre->nxtt=NULL;
l=pre;
}
else
cout<<" Not Able to Delete";
break;
case 3:
cout<<" Enter the Position of Deletion:";
cin>>posi;
while(countr!=posi)
{
pre=curr;
curr=curr->nxtt;
countr++;
}
if(countr==posi)
{
cout<<" Deleted Element is: "<<curr->dataa;
pre->nxtt=curr->nxtt;
}
else
cout<<" Not Able to Delete";
break;
}
}
void List::display()
{
Node *tmp=f;
if(tmp==NULL)
{
cout<<" List is Empty";
}
while(tmp!=NULL)
{
cout<<tmp->dataa;
cout<<"-->";
tmp=tmp->nxtt;
}
cout<<"NULL";
}
void List::search()
{
int value,posi=0;
bool flag=false;
if(f==NULL)
{
cout<<"List is Empty";
return;
}
cout<<"Enter the Value to be Searched:";
cin>>value;
Node *tmp;
tmp=f;
while(tmp!=NULL)
{
posi++;
if(tmp->dataa==value)
{
flag=true;
cout<<"Element"<<value<<"is Found at "<<posi<<" Position";
return;
}
tmp=tmp->nxtt;
}
if(!flag)
{
cout<<"Element "<<value<<" not Found in the List";
}
}
int main()
{
List l;
int choice;
while(1)
{
cout<<" **** MENU ****";
cout<<" 1:CREATE 2:INSERT 3:DELETE 4:SEARCH 5:DISPLAY 6:EXIT ";
cout<<" Enter Your Choice:";
cin>>choice;
switch(choice)
{
case 1:
l.create();
break;
case 2:
l.insert();
break;
case 3:
l.delet();
break;
case 4:
l.search();
break;
case 5:
l.display();
break;
case 6:
return 0;
}
}
return 0;
}