Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

C++ Implement a class template for a LinkedList.(doubly linked). Also, your class will have a tailPtr in addition to a headPtr along with methods to

C++

Implement a class template for a LinkedList.(doubly linked). Also, your class will have a tailPtr in addition to a headPtr along with methods to get, set, insert and remove values at either end of the list. Call these getFirst, getLast, setFirst, setLast, insertFirst, insertLast, removeFirst, removeLast. Don't forget, you also need a copy constructor and destructor plus getLength, isEmpty and clear methods. Overload the stream insertion operator as a friend function which outputs the list in format { 1, 4, 7 } (enclosing braces and comma + space between values). Finally, you'll implement insertAtPosition and removeAtPosition, each of which takes two parameters: the first of type T and the second of type int and inserts or removes a value equal to the first parameter at the position equal to the second parameter. Legal values for the second parameter are from 1 to the list length + 1 for insert and from 1 to the list length for the remove. Out of range values have no effect. BTW positions start with 1 unlike array indexes which start with 0.

#ifndef LINKEDLIST_H_INCLUDED #define LINKEDLIST_H_INCLUDED #include #include #include

using namespace std; template struct Node { T data; Node *Next, *Previous; };

template class Linkedlist { private: Node *First = NULL; Node *Last = NULL; Node *Middle = NULL; Node *TempPrevious; Node *TempNext; Node *P; int length;

public: Linkedlist() { First = NULL; Last = NULL; length = 0; }

void insertfirst(const T & data) T getfirst()const; T getlast()const; void setfirst(const T &d); void setlast(const T &d); void insertlast(const T & d); void removefirst(); //no parameters void removelast(); int getlength(const); bool isEmpty()const; void clear(); void insertatposition( const T &d, int position);

};

#endif // LINKEDLIST_H_INCLUDED

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Intelligent Databases Technologies And Applications

Authors: Zongmin Ma

1st Edition

1599041219, 978-1599041216

More Books

Students also viewed these Databases questions

Question

7. Identify six intercultural communication dialectics.

Answered: 1 week ago