Question
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
using namespace std; template
template
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
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started