Write an additional method called push_back(int) that will

 

1.Write an additional method called push_back(int) that will add an integer to the end of the list. You can modify the provided code. 2.Modify the Node class and LinkedList class so that you can access your parent node (double linked-list).

#include

#include

using namespace std;

typedef int Type;

enum Boolean

{

False = 0, True

};

class Item

{

friend class SLList;

public:

Type getVal()

{

return val;

}

private:

Item(Type value, Item *item = 0)

{

val = value;

next = item;

}

Type val;

Item *next;

};

class SLList

{

public:

class Const_Iterator

{

friend class SLList;

public:

Item *current;

Const_Iterator() :

current(NULL)

{

}

const Item & operator*() const

{

return *this->current;

}

Const_Iterator operator++()

{

current = current->next;

return *this;

}

Const_Iterator operator++(int)

{

Const_Iterator old = *this;

++(*this);

return old;

}

bool operator==(const Const_Iterator & rhs)

{

return current == rhs.current;

}

bool operator!=(const Const_Iterator & rhs)

{

return !(*this == rhs);

}

Item retrieve() const

{

return current->val;

}

Const_Iterator(Item *p) :

current(p)

{

}

};

class Iterator

{

friend class SLList;

public:

Item *current;

Iterator() :

current(NULL)

{

}

const Item & operator*() const

{

return *this->current;

}

Iterator operator++()

{

current = current->next;

return *this;

}

Iterator operator++(int)

{

Iterator old = *this;

++(*this);

return old;

}

bool operator==(const Iterator & rhs) const

{

return current == rhs.current;

}

bool operator!=(const Iterator & rhs)

{

return !(*this == rhs);

}

Item retrieve()

{

return current->val;

}

Iterator(Item *p) :

current(p)

{

}

};

SLList()

{

list = 0;

}

~SLList()

{

remove();

}

void insert(Type someItem);

void append(Type someItem);

int remove(Type someItem);

void remove();

Item *atEnd();

Item *head();

Item *tail();

Boolean isPresent(Type someItem);

Boolean isEmpty();

void display();

private:

Iterator iterator;

Item *list;

Item *atEndItem;

};

Boolean SLList::isEmpty()

{

return list == 0 ? True : False;

}

void SLList::insert(Type val)

{

Item *pt = new Item(val, list); // create new item put it in front of list

assert(pt != 0);

if (list == 0)

{

atEndItem = pt;

}

list = pt; // and point next top the list

}

Item *SLList::atEnd()

{

if (list == 0)

{

return 0;

}

Item *prev, *curr;

prev = curr = list;

while (curr)

{

prev = curr;

curr = curr->next;

}

return prev;

}

Item *SLList::tail()

{

if (list == 0)

{

return 0;

}

Item *prev, *curr;

prev = curr = list;

while (curr)

{

prev = curr;

curr = curr->next;

}

return prev;

}

Item *SLList::head()

{

if (list == 0)

{

cout << “List is empty” << endl;

return 0;

}

else

{

return list;

} // end if

return list;

}

void SLList::append(Type val)

{

Item *pt = new Item(val);

assert(pt != 0);

if (list == 0)

{

list = pt;

}

else

{

atEndItem->next = pt;

}

atEndItem = pt;

}

void SLList::display()

{

cout << “(“;

for (Item *pt = list; pt; pt = pt->next)

{

cout << pt->val << ” “;

} // end for

cout << “)” << endl;

}

void SLList::remove()

{

Item *pt = list;

while (pt)

{

Item *temp = pt;

pt = pt->next;

delete temp;

} // end while

list = atEndItem = 0;

}

Boolean SLList::isPresent(Type item)

{

Boolean rc = False;

if (list != 0)

{

if (list->val == item || atEndItem->val == item)

{

rc = True;

}

else

{

Item *pt = list->next;

for (; pt != atEndItem; pt = pt->next)

{

if (pt->val == item)

{

rc = True;

} // end if

} // end for

} // end if

} // end if

return rc;

}

int SLList::remove(Type val)

{

Item *pt = list;

int cnt = 0;

while (pt && pt->val == val)

{

Item *tmp = pt->next;

delete pt;

cnt++;

pt = tmp;

} // end while

if ((list = pt) == 0)

{

atEndItem = 0;

return cnt;

} // end if

Item *prv = pt;

pt = pt->next;

while (pt)

{

if (pt->val == val)

{

prv->next = pt->next;

if (atEndItem == pt)

{

atEndItem = prv;

} // end if

delete pt;

++cnt;

pt = prv->next;

}

else

{

prv = pt;

pt = pt->next;

} // end if else

} // end while

return cnt;

}

int main()

{

cout << “Single Linked List Example” << endl;

const int size = 12;

const int odd = 1;

int ix = 0;

SLList il;

SLList::Iterator itr;

if (il.isEmpty() != True || il.isPresent(1024) != False)

{

cerr << “List class internal error (1)” << endl;

}

else

{

cout << “Ok, empty list class” << endl;

} // end ifelse

il.remove(1024);

il.display();

for (ix = 0; ix < size; ++ix)

{

il.append(ix % 2 ? odd : ix);

} // end for

il.display();

if (il.isEmpty() == False)

{

cout << ” Head ” << il.head()->getVal() << endl;

cout << ” Tail ” << il.tail()->getVal() << endl;

} // end if

if (il.isPresent(odd) != True)

{

cerr << “List class internal error (2)” << endl;

} // end if

int odd_cnt = il.remove(odd);

cout << odd_cnt << ” items of value ” << odd << ” removed.” << endl;

il.display();

if (il.isEmpty() == False)

{

cout << ” Head ” << il.head()->getVal() << endl;

cout << ” Tail ” << il.tail()->getVal() << endl;

} // end if

for (ix = 0; ix < odd_cnt; ++ix)

{

il.insert(odd);

} // end for

il.display();

if (il.isEmpty() == False)

{

cout << ” Head ” << il.head()->getVal() << endl;

cout << ” Tail ” << il.tail()->getVal() << endl;

} // end if

for (itr = il.head(); itr != il.tail(); itr++)

{

cout << “Itr = ” << itr.current->getVal()<< endl;

} // end for

il.remove();

il.display();

if (il.isEmpty() == False)

{

cout << ” Head ” << il.head()->getVal() << endl;

cout << ” Tail ” << il.tail()->getVal() << endl;

} // end if

return 0;

}

Duepapers
Calculate your paper price
Pages (550 words)
Approximate price: -

Why Work with Us

Top Quality and Well-Researched Papers

We always make sure that writers follow all your instructions precisely. You can choose your academic level: high school, college/university or professional, and we will assign a writer who has a respective degree.

Professional and Experienced Academic Writers

We have a team of professional writers with experience in academic and business writing. Many are native speakers and able to perform any task for which you need help.

Free Unlimited Revisions

If you think we missed something, send your order for a free revision. You have 10 days to submit the order for review after you have received the final document. You can do this yourself after logging into your personal account or by contacting our support.

Prompt Delivery and 100% Money-Back-Guarantee

All papers are always delivered on time. In case we need more time to master your paper, we may contact you regarding the deadline extension. In case you cannot provide us with more time, a 100% refund is guaranteed.

Original & Confidential

We use several writing tools checks to ensure that all documents you receive are free from plagiarism. Our editors carefully review all quotations in the text. We also promise maximum confidentiality in all of our services.

24/7 Customer Support

Our support agents are available 24 hours a day 7 days a week and committed to providing you with the best customer experience. Get in touch whenever you need any assistance.

Try it now!

Calculate the price of your order

Total price:
$0.00

How it works?

Follow these simple steps to get your paper done

Place your order

Fill in the order form and provide all details of your assignment.

Proceed with the payment

Choose the payment system that suits you most.

Receive the final file

Once your paper is ready, we will email it to you.

Our Services

No need to work on your paper at night. Sleep tight, we will cover your back. We offer all kinds of writing services.

Essays

Essay Writing Service

No matter what kind of academic paper you need and how urgent you need it, you are welcome to choose your academic level and the type of your paper at an affordable price. We take care of all your paper needs and give a 24/7 customer care support system.

Admissions

Admission Essays & Business Writing Help

An admission essay is an essay or other written statement by a candidate, often a potential student enrolling in a college, university, or graduate school. You can be rest assurred that through our service we will write the best admission essay for you.

Reviews

Editing Support

Our academic writers and editors make the necessary changes to your paper so that it is polished. We also format your document by correctly quoting the sources and creating reference lists in the formats APA, Harvard, MLA, Chicago / Turabian.

Reviews

Revision Support

If you think your paper could be improved, you can request a review. In this case, your paper will be checked by the writer or assigned to an editor. You can use this option as many times as you see fit. This is free because we want you to be completely satisfied with the service offered.