?!?, | 2.El. || Heading 611NorrnalI1NoSpac Heading 2 Heading 1 Heading 7 Title P
ID: 3706729 • Letter: #
Question
?!?, | 2.El. || Heading 611NorrnalI1NoSpac Heading 2 Heading 1 Heading 7 Title Paragraph Styles COSC 1437 S70 Lab 5-10% Program Requirements: Create a LinkList class to hold integers. Read the integers from standard input until 0 is entered-the integers should be maintained in the increasing order in the LinkList Constructor- one with a pointer to an integer as parameter to create a LinkList with one node. Insert fiunction (InsertElement: Takes an integer and inserts it in the correct place in the list Print function (PrintList): Display the integers in the list Delete Function (DeleteElement): Takes an integer and deletes from the list if found. Search function (SearchElement): Searching an integer in the list. The return type must be boolean (False if not found else True) To Turn In: Email code with the subject line "COSC 1437.S70 -Lab S" Include the main function to test the code for the functionality of the class. The program should be developed in Visual StudioExplanation / Answer
#include<iostream>
using namespace std;
class node
{
public:
int data;//to store integers
node *next,*prev;//links
//constructor
public:
node(int d){
data=d;
next=NULL;
prev = NULL;
}
};
class linkedlist
{
node *head,*tail;
public:
//constructor..
linkedlist(int *p)
{
head = new node(*p);//creating a node...
tail = head;
}
void insert(int d)
{
node *temp=head;
//placing new node at correct position
while(temp!=NULL)
{
if(temp->data>d)
break;
temp=temp->next;
}
//placing node
if(temp==NULL)
{
tail->next=new node(d);
tail->next->prev =tail;
tail = tail->next;
}
else if(temp->prev==NULL)
{
temp->prev = new node(d);
temp->prev->next = temp;
head =temp;
}
else
{
node *temp2 = new node(d);
temp2->prev = temp->prev;
temp2->next = temp;
temp->prev = temp2;
}
}
void Delete(int d)
{
node *temp=head;
//finding node position
while(temp!=NULL)
{
if(temp->data==d)
break;
temp=temp->next;
}
//removing node
temp->prev->next= temp->next;
temp->next->prev = temp->prev;
}
bool search(int d)
{
node *temp=head;
//finding node position
while(temp!=NULL)
{
if(temp->data==d)
return true;//if found
temp=temp->next;
}
//if not found
return false;
}
};
int main()
{
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.