Close Lab: Practicing LinkedList The objective of this close lab is to practice
ID: 3695027 • Letter: C
Question
Close Lab: Practicing LinkedList
The objective of this close lab is to practice linked list.
Please write in basic c++ code and nothing too advanced please
Assignment:
Complete the definition of the template linklist class below,
template <typename T>
class LinkList
{ private:
class Node
{
public:
T info;
Node *next;
};
typedef Node *nodePtr;
public:
LinkList(); //constructor
LinkList(const LinkList<T> & orig); //copy constructor
bool empty(); //determine if the LinkList is empty
T Front(); // returns item at front of LinkList
T Back(); // returns item at back of LinkList
Void PrintSecond();//print the content of the second node
void Push_front(const T & item);
//add item at the begining of LinkList
void pop_back(); //remove the last item of the LinkList
// Search function to search a given value and return the count
// of the given value
_______________________________________________________
// Pop_front function to remove the first item of the LinkList.
___________________________________________________________
// push_back function to add an item at the end of the LinkList
____________________________________________________________
private:
// node pointer which points to the front(first node)
____________________________________________________
};
Complete the implementation of the following member functions: Search(), Front(), Back(), PrintSecond(), Pop_front() and Push_back(), and then write a test driver to fully test your linklist.
Explanation / Answer
//
// File: linkedlist.h
// Author: RAM
//
// Created on 27 April, 2016, 11:50PM
//
#ifndef _LINKEDLIST_H
#define _LINKEDLIST_H
class LinkList
{
private:
class Node
{
public:
T info;
Node *next;
};
typedef Node *nodePtr;
public:
LinkList(); //constructor
LinkList(const LinkList<T> & orig); //copy constructor
bool empty(); //determine if the LinkList is empty
T Front(); // returns item at front of LinkList
T Back(); // returns item at back of LinkList
void PrintSecond();//print the content of the second node
void Push_front(const T & item);
//add item at the begining of LinkList
void pop_back(); //remove the last item of the LinkList
// Search function to search a given value and return the count
// of the given value
_______________________________________________________
// Pop_front function to remove the first item of the LinkList.
___________________________________________________________
// push_back function to add an item at the end of the LinkList
____________________________________________________________
private:
// node pointer which points to the front(first node)
____________________________________________________
};
#endif /* _LINKEDLIST_H */
//constructor
template <class T>
LinkedList<T>::LinkedList()
{
first = NULL;
last = NULL;
}
template <class T>
T LinkedList<T>::print()
{
Node<T>* temp = first;
if (temp == NULL)
{
cout<<"";
}
if (temp->next == NULL)
{
cout<<temp->val;
}
else
{
while (temp != NULL)
{
cout<< temp->val;
temp = temp->next;
cout<< ",";
}
}
}
template <class T>
T LinkedList<T>::Front(T valueToInsert)
{
Node<T>* newNode;
newNode->val = valueToInsert;
if(first == NULL)
{
first = newNode;
}
else
{
newNode->next = first;
first = newNode;
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.