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

Design and implement a class representing a sorted circular doubly linked list.

ID: 3740809 • Letter: D

Question

Design and implement a class representing a sorted circular doubly linked list. The class must harve the eouree als Add an item to the list. 1. The class mvust be a template clas 2. The class must have one private field member, called first, which has the address of the first node in the 3. The class must have no other field members 4. The class must include the following methods: e an item from the iat List for a given itom. coutee"ls6 Print the mumber o eoutee in7s Terminate the programiain iten in the ist given inemm j. A function to insert a given item L. A function to search a given inems-returns truc if Sound. m. A function to prints all items in the list-prit Jist is empty if there no items coutex InEster the number to insece" Test your class with the stdy t priathens displays a mena of eholces and returne uer's choice ertList isserts an item into the list 1, it the liat is t ful deletelList deletes an iten from the list, it iton in the 1 to del printa the tumber of items in the li cout et operat os od on the list of integers are bow choice pr er the number of your choice and preas reurn-nte tion failedi no itema in ehe list.inin do ( case1 tinsertliatitem(1) case 2 1deletelistitem (1) esse 3 #2.makebpty[ case 5 1searehiaticem (11 so itema in the 11st.nin" default '1oout"Inunber Ls not correet. P Please renter

Explanation / Answer

struct node

{

node *next, *prev;

int data;

};

class double_sclist

{

struct node* head;

public:

void insert(int x);

void delete(int x);

void search(int x);

void makeEmpty();

bool isEmpty();

bool isFull();

int size();

void display();

void copy(double_sclist obj);

void operator = (const double_sclist &obj);

double_sclist();

~double_sclist();

double_sclist(const double_sclist &dlist)

};

double_sclist::double_sclist()

{

start = NULL;

last = NULL;

}

void double_sclist::insert(int x)

{

struct node* np = new node;

struct node* p;

struct node* r;

np->data = x;

np->next = NULL;

np->prev = NULL;

if (c == 0)

{

tail = np;

head = np;

p = head;

p->next = head;

p->prev = head;

c++;

}

else if (c == 1)

{

p = head;

r = p;

if (np->data < p->data)

{

np->next = p;

p->prev = np;

head = np;

p->next = np;

np->prev = p;

}

else if (np->data > p->data)

{

p->next = np;

np->prev = p;

np->next = head;

p->prev = np;

}

c++;

} else {

p = head;

r = p;

if (np->data < p->data)

{

np->next = p;

p->prev = np;

head = np;

do

{

p = p->next;

}

while (p->next != r);

p->next = np;

np->prev = p;

}

else if (np->data > p->data)

{

while (p->next != head && np->data > p->data)

{

r = p;

p = p->next;

if (p->next == head && (p->data < np->data))

{

p->next = np;

np->prev = p;

np->next = head;

head->prev = np;

break;

}

else if (np->data < p->data)

{

r->next = np;

np->prev = r;

np->next = p;

p->prev = np;

if (p->next != head)

{

do

{

p = p->next;

}

while (p->next != head);

}

break;

}

}

}

}

}

void double_sclist::delete(int x){

node *t = head;

while (t!= NULL&&t!=head&&t->next-data!=x)

{

t = t->next;

}

if(t->next->data==x){

t->next->next->prev=t;

t->next=t->next->next;

}

cout<<endl;

}

bool double_sclist::search(int x){

node *t = head;

while (t!= NULL&&t!=head)

{

t = t->next;

if(t->data==x)

return true;

}

return false;

}

void double_sclist::makeEmpty(){

this->head=NULL;

}

bool double_sclist::isEmpty(){

return (this->head==NULL);

}

bool double_sclist::isEmpty(){

return (this->head!=NULL);

}

int double_sclist::size(){

struct node* temp = head;

int result = 0;

if (head != NULL) {

do {

temp = temp->next;

result++;

} while (temp != head);

}

return result;

}

void double_sclist::display(){

struct Node* temp = head;

if (head != NULL) {

do {

cout<<temp->data<<endl;

temp = temp->next;

} while (temp != head);

}

}

double_sclist::~double_sclist(){

free(head);

}

double_sclist::double_sclist(const double_sclist &dlist){

this->head=dlist.head;

}

void operator = (double_sclist const &obj) {

double_sclist res;

res.head = obj.head;

return res;

}

void double_sclist::copy(double_sclist obj){

this->head=obj.head;

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote