SlideShare a Scribd company logo
1 of 7
Download to read offline
Template LinkedList;
I am using templates to make some linkedLists
Here is the Data and next pointer class:
and here is my header where i do the implementations, aswell as an explanation as to what the
functions should do
Can anybody please help me with the implementations so i can get a better understanding?
Thankyou very much in advance!
(If possible please answer from a computer :D) 1 #pragma once 1 3 template typename T 4 E
class Node public 7 I ode( T(), Node
Solution
LLToolkit.h
#ifndef LLTOOLKIT_H_
#define LLTOOLKIT_H_
#include
#include "Node.h"
using namespace std;
template
class LLToolkit
{
public:
// Precondition: headPtr points to the head of a list
// Postcondition: Info has been inserted at the head of the list, and headPtr is updated
void headInsert(Node*& headPtr, T data)
{
headPtr = new Node(data, headPtr);
}
// Precondition: headPtr points to the head of a list with at least 1 element
// Postcondition: The head element has been removed and headPtr is updated to point to the
new
// head element
void headRemove(Node*& headPtr)
{
if (headPtr != NULL)
{
Node* condemned = headPtr;
headPtr = headPtr->next;
delete condemned;
}
}
// Precondition: prevPtr points to Node just before insertion point
// Postcondition: A new Node with data=info has been inserted into the list after prevPtr
void insert(Node*& prevPtr, T data)
{
if (prevPtr == NULL) return;
Node* next = prevPtr->next;
prevPtr->next = new Node(data, next);
}
// Precondition: prevPtr points to Node just before Node to remove
// Postcondition: The Node after prevPtr has been removed from the list
void remove(Node*& prevPtr)
{
if (prevPtr == NULL) return;
if (prevPtr->next == NULL) return;
Node* condemned = prevPtr->next;
prevPtr->next = condemned->next;
delete prevPtr->next;
}
// Precondition: sourcePtr is the head pointer of a linked list.
// Postcondition: A pointer to a copy of the linked list is returned. The original list is
// unaltered.
Node* copy(Node* sourcePtr)
{
Node* headPtr = NULL; // Head pointer for new list
Node* tailPtr = NULL;
// Handle the case of the empty list.
if (sourcePtr == NULL) return headPtr;
// Make the head LLNode for the newly created list, and put data in it.
headInsert(headPtr, sourcePtr->info);
tailPtr = headPtr;
// Copy the rest of the nodes one at a time, adding at the tail of new list.
sourcePtr = sourcePtr->next;
while (sourcePtr != NULL)
{
insert(tailPtr, sourcePtr->info);
tailPtr = tailPtr->next;
sourcePtr = sourcePtr->next;
}
return headPtr;
}
// Precondition: headPtr is the head pointer of a linked list.
// Postcondition: All nodes of the list have been deleted, and the headPtr is NULL.
void clear(Node* headPtr)
{
while (headPtr != NULL)
{
Node* prevPtr = headPtr;
headPtr = headPtr->next;
delete prevPtr;
}
return headPtr;
}
// Precondition: headPtr is the head pointer of a linked list.
// Postcondition: The data item of each Node in the list has been printed to the screen in an
// easily readable way, e.g. 3 - 4 - 7 -/
void print(Node* headPtr)
{
while (headPtr != NULL)
{
cout << headPtr->info << endl;
headPtr = headPtr->next;
}
}
// Precondition: headPtr is the head pointer of a linked list.
// Postcondition: headPtr points to the start of a list that is reversed with respect to the
// original list
void reverse(Node*& headPtr)
{
Node* tempPtr = NULL; // Head pointer for new list
// Handle the case of the empty list.
if (headPtr == NULL)
{
cout << "Can't reverse an empty list" << endl;
return;
}
// Copy the rest of the nodes one at a time, adding at the tail of new list.
while (headPtr != NULL)
{
headInsert(tempPtr, headPtr->info);
headPtr = headPtr->next;
}
headPtr = tempPtr;
}
// Precondition: splitPtr points to the node before the split point
// Postcondition: A pointer is returned that points to the first node after splitPtr. The
// original list ends at the node pointed to by splitPtr
Node* split(Node* splitPtr)
{
Node* newHeadPtr = splitPtr->next;
splitPtr->next = NULL;
return newHeadPtr;
}
// Precondition: values points to an array of at least size n
// Postcondition: A pointer is returned that points to the head of a list in which the nodes
// contains values from the array values
Node* build(int* values, size_t n)
{
Node* headPtr = NULL; // Head pointer for new list
Node* tailPtr = NULL;
// Make the head LLNode for the newly created list, and put data in it.
headInsert(headPtr, values[0]);
tailPtr = headPtr;
for (int i = 1; i < n; i++)
{
insert(tailPtr, values[i]);
tailPtr = tailPtr->next;
}
return headPtr;
}
// Precondition: head1 and head2 each point to the head of linked lists
// Postcondition: head1 points to a list containing head1-lists' elements followed by head2-
lists
// element.
void join(Node* head1, Node* head2)
{
Node *tailPtr;
//krer en lkke for at finde sidste plads
//i head1 s listerne kan sttes sammen.
while (head1 != NULL)
{
tailPtr = head1;
head1 = head1->next;
}
//TailPtr bliver nu brugt til at stte de lister sammen
tailPtr->next = head2;
}
// Precondition: head points to the head of a linked list
// Postcondition: The list is rotated left by once - if it was 1-2-3-4, it is now 2-3-4-1
void rotateLeft(Node*& headPtr)
{
Node *tailPtr;
Node *tempPtr = headPtr;
//krer en lkke for at finde sidste vrdi i listen
while (tempPtr != NULL)
{
tailPtr = tempPtr;
tempPtr = tempPtr->next;
}
insert(tailPtr, headPtr->info);
headPtr = headPtr->next;
}
// Precondition: head points to the head of a linked list
// Postcondition: The list is rotated right once - if it was 1-2-3-4, it is now 4-1-2-3
void rotateRight(Node*& head)
{
Node *tailPtr;
Node *tempPtr = head;
//en while lkke til at finde den sidste vrdi i den linkede liste
while (tempPtr->next != NULL)
{
tailPtr = tempPtr;
tempPtr = tempPtr->next;
}
headInsert(head, tempPtr->info);
tailPtr->next = NULL;
delete tempPtr;
}
};
#endif // LLTOOLKIT_H_
Node.h
#ifndef NODE_H_
#define NODE_H_
#include
template
class Node
{
public:
Node(const T& i = T(), Node* n = NULL)
: info(i), next(n)
{
}
T info;
Node* next;
};
#endif // NODE_H_

More Related Content

Similar to Template LinkedList;I am using templates to make some linkedLists.pdf

c++ Computational Complexity filling in the following three .pdf
c++ Computational Complexity filling in the  following three .pdfc++ Computational Complexity filling in the  following three .pdf
c++ Computational Complexity filling in the following three .pdfamitbagga0808
 
Implement the following specification of UnsortedType using circular.pdf
Implement the following specification of UnsortedType using circular.pdfImplement the following specification of UnsortedType using circular.pdf
Implement the following specification of UnsortedType using circular.pdfudit652068
 
C++Write a method Node Nodereverse() which reverses a list..pdf
C++Write a method Node Nodereverse() which reverses a list..pdfC++Write a method Node Nodereverse() which reverses a list..pdf
C++Write a method Node Nodereverse() which reverses a list..pdfarjunenterprises1978
 
linked list.pptx
linked list.pptxlinked list.pptx
linked list.pptxchin463670
 
C++ problemPart 1 Recursive Print (40 pts)Please write the recu.pdf
C++ problemPart 1 Recursive Print (40 pts)Please write the recu.pdfC++ problemPart 1 Recursive Print (40 pts)Please write the recu.pdf
C++ problemPart 1 Recursive Print (40 pts)Please write the recu.pdfcallawaycorb73779
 
The algorithm to reverse a linked list by rearranging the required p.pdf
The algorithm to reverse a linked list by rearranging the required p.pdfThe algorithm to reverse a linked list by rearranging the required p.pdf
The algorithm to reverse a linked list by rearranging the required p.pdfaradhana9856
 
--INSTRUCTION- --It helps to first create if-then-else structure to fi.pdf
--INSTRUCTION- --It helps to first create if-then-else structure to fi.pdf--INSTRUCTION- --It helps to first create if-then-else structure to fi.pdf
--INSTRUCTION- --It helps to first create if-then-else structure to fi.pdfAdrianEBJKingr
 
The LinkedList1 class implements a Linked list. class.pdf
The LinkedList1 class implements a Linked list. class.pdfThe LinkedList1 class implements a Linked list. class.pdf
The LinkedList1 class implements a Linked list. class.pdfmalavshah9013
 
Linked list and its operations - Traversal
Linked list and its operations - TraversalLinked list and its operations - Traversal
Linked list and its operations - Traversalkasthurimukila
 
C++ please put everthing after you answer it- thanks Complete the stub.docx
C++ please put everthing after you answer it- thanks Complete the stub.docxC++ please put everthing after you answer it- thanks Complete the stub.docx
C++ please put everthing after you answer it- thanks Complete the stub.docxMatthPYNashd
 
linked List.docx vhjgvjhvgjhjhbbjkhkjhkjh
linked List.docx vhjgvjhvgjhjhbbjkhkjhkjhlinked List.docx vhjgvjhvgjhjhbbjkhkjhkjh
linked List.docx vhjgvjhvgjhjhbbjkhkjhkjhvasavim9
 
Please correct my errors upvote Clears our entire .pdf
Please correct my errors upvote      Clears our entire .pdfPlease correct my errors upvote      Clears our entire .pdf
Please correct my errors upvote Clears our entire .pdfkitty811
 
Need Help!! C++ #include-iostream- #include-linkedlist-h- using namesp.pdf
Need Help!! C++ #include-iostream- #include-linkedlist-h- using namesp.pdfNeed Help!! C++ #include-iostream- #include-linkedlist-h- using namesp.pdf
Need Help!! C++ #include-iostream- #include-linkedlist-h- using namesp.pdfEdwardw5nSlaterl
 
COMP2710: Software Construction - Linked list exercises
COMP2710: Software Construction - Linked list exercisesCOMP2710: Software Construction - Linked list exercises
COMP2710: Software Construction - Linked list exercisesXiao Qin
 
How to do insertion sort on a singly linked list with no header usin.pdf
How to do insertion sort on a singly linked list with no header usin.pdfHow to do insertion sort on a singly linked list with no header usin.pdf
How to do insertion sort on a singly linked list with no header usin.pdfarihantelehyb
 
using the single linked list code written in the class or in the lab,.pdf
using the single linked list code written in the class or in the lab,.pdfusing the single linked list code written in the class or in the lab,.pdf
using the single linked list code written in the class or in the lab,.pdfRBMADU
 

Similar to Template LinkedList;I am using templates to make some linkedLists.pdf (20)

c++ Computational Complexity filling in the following three .pdf
c++ Computational Complexity filling in the  following three .pdfc++ Computational Complexity filling in the  following three .pdf
c++ Computational Complexity filling in the following three .pdf
 
Implement the following specification of UnsortedType using circular.pdf
Implement the following specification of UnsortedType using circular.pdfImplement the following specification of UnsortedType using circular.pdf
Implement the following specification of UnsortedType using circular.pdf
 
DSA(1).pptx
DSA(1).pptxDSA(1).pptx
DSA(1).pptx
 
C++Write a method Node Nodereverse() which reverses a list..pdf
C++Write a method Node Nodereverse() which reverses a list..pdfC++Write a method Node Nodereverse() which reverses a list..pdf
C++Write a method Node Nodereverse() which reverses a list..pdf
 
linked list.pptx
linked list.pptxlinked list.pptx
linked list.pptx
 
Ll.pptx
Ll.pptxLl.pptx
Ll.pptx
 
C++ problemPart 1 Recursive Print (40 pts)Please write the recu.pdf
C++ problemPart 1 Recursive Print (40 pts)Please write the recu.pdfC++ problemPart 1 Recursive Print (40 pts)Please write the recu.pdf
C++ problemPart 1 Recursive Print (40 pts)Please write the recu.pdf
 
The algorithm to reverse a linked list by rearranging the required p.pdf
The algorithm to reverse a linked list by rearranging the required p.pdfThe algorithm to reverse a linked list by rearranging the required p.pdf
The algorithm to reverse a linked list by rearranging the required p.pdf
 
--INSTRUCTION- --It helps to first create if-then-else structure to fi.pdf
--INSTRUCTION- --It helps to first create if-then-else structure to fi.pdf--INSTRUCTION- --It helps to first create if-then-else structure to fi.pdf
--INSTRUCTION- --It helps to first create if-then-else structure to fi.pdf
 
The LinkedList1 class implements a Linked list. class.pdf
The LinkedList1 class implements a Linked list. class.pdfThe LinkedList1 class implements a Linked list. class.pdf
The LinkedList1 class implements a Linked list. class.pdf
 
Linked list and its operations - Traversal
Linked list and its operations - TraversalLinked list and its operations - Traversal
Linked list and its operations - Traversal
 
Unit7 C
Unit7 CUnit7 C
Unit7 C
 
Linked list
Linked listLinked list
Linked list
 
C++ please put everthing after you answer it- thanks Complete the stub.docx
C++ please put everthing after you answer it- thanks Complete the stub.docxC++ please put everthing after you answer it- thanks Complete the stub.docx
C++ please put everthing after you answer it- thanks Complete the stub.docx
 
linked List.docx vhjgvjhvgjhjhbbjkhkjhkjh
linked List.docx vhjgvjhvgjhjhbbjkhkjhkjhlinked List.docx vhjgvjhvgjhjhbbjkhkjhkjh
linked List.docx vhjgvjhvgjhjhbbjkhkjhkjh
 
Please correct my errors upvote Clears our entire .pdf
Please correct my errors upvote      Clears our entire .pdfPlease correct my errors upvote      Clears our entire .pdf
Please correct my errors upvote Clears our entire .pdf
 
Need Help!! C++ #include-iostream- #include-linkedlist-h- using namesp.pdf
Need Help!! C++ #include-iostream- #include-linkedlist-h- using namesp.pdfNeed Help!! C++ #include-iostream- #include-linkedlist-h- using namesp.pdf
Need Help!! C++ #include-iostream- #include-linkedlist-h- using namesp.pdf
 
COMP2710: Software Construction - Linked list exercises
COMP2710: Software Construction - Linked list exercisesCOMP2710: Software Construction - Linked list exercises
COMP2710: Software Construction - Linked list exercises
 
How to do insertion sort on a singly linked list with no header usin.pdf
How to do insertion sort on a singly linked list with no header usin.pdfHow to do insertion sort on a singly linked list with no header usin.pdf
How to do insertion sort on a singly linked list with no header usin.pdf
 
using the single linked list code written in the class or in the lab,.pdf
using the single linked list code written in the class or in the lab,.pdfusing the single linked list code written in the class or in the lab,.pdf
using the single linked list code written in the class or in the lab,.pdf
 

More from fatoryoutlets

Write an informal paper that is exactly 3 pages long not counting th.pdf
Write an informal paper that is exactly 3 pages long not counting th.pdfWrite an informal paper that is exactly 3 pages long not counting th.pdf
Write an informal paper that is exactly 3 pages long not counting th.pdffatoryoutlets
 
Write a C program to find factorial of an integer n, where the user .pdf
Write a C program to find factorial of an integer n, where the user .pdfWrite a C program to find factorial of an integer n, where the user .pdf
Write a C program to find factorial of an integer n, where the user .pdffatoryoutlets
 
When was the black body mutation in drosophila melanogaster discover.pdf
When was the black body mutation in drosophila melanogaster discover.pdfWhen was the black body mutation in drosophila melanogaster discover.pdf
When was the black body mutation in drosophila melanogaster discover.pdffatoryoutlets
 
What is it that consumer researchers try to find among varying cultu.pdf
What is it that consumer researchers try to find among varying cultu.pdfWhat is it that consumer researchers try to find among varying cultu.pdf
What is it that consumer researchers try to find among varying cultu.pdffatoryoutlets
 
What are pros and cons of Symantec endpoint security softwareSo.pdf
What are pros and cons of Symantec endpoint security softwareSo.pdfWhat are pros and cons of Symantec endpoint security softwareSo.pdf
What are pros and cons of Symantec endpoint security softwareSo.pdffatoryoutlets
 
All of the following describe the International Accounting Standard .pdf
All of the following describe the International Accounting Standard .pdfAll of the following describe the International Accounting Standard .pdf
All of the following describe the International Accounting Standard .pdffatoryoutlets
 
The right and left sternocleidomastoid muscles of humans originate o.pdf
The right and left sternocleidomastoid muscles of humans originate o.pdfThe right and left sternocleidomastoid muscles of humans originate o.pdf
The right and left sternocleidomastoid muscles of humans originate o.pdffatoryoutlets
 
The code in image3.cpp has the error as shown above, could you help .pdf
The code in image3.cpp has the error as shown above, could you help .pdfThe code in image3.cpp has the error as shown above, could you help .pdf
The code in image3.cpp has the error as shown above, could you help .pdffatoryoutlets
 
the ability of the cardiac muscle cells to fire on their own is .pdf
the ability of the cardiac muscle cells to fire on their own is .pdfthe ability of the cardiac muscle cells to fire on their own is .pdf
the ability of the cardiac muscle cells to fire on their own is .pdffatoryoutlets
 
Surface water entering the North Atlantic may have a temperature of .pdf
Surface water entering the North Atlantic may have a temperature of .pdfSurface water entering the North Atlantic may have a temperature of .pdf
Surface water entering the North Atlantic may have a temperature of .pdffatoryoutlets
 
Suppose the rate of plant growth on Isle Royale supported an equilib.pdf
Suppose the rate of plant growth on Isle Royale supported an equilib.pdfSuppose the rate of plant growth on Isle Royale supported an equilib.pdf
Suppose the rate of plant growth on Isle Royale supported an equilib.pdffatoryoutlets
 
Q1. public void operationZ() throws StackUnderflowException {   .pdf
Q1. public void operationZ() throws StackUnderflowException {   .pdfQ1. public void operationZ() throws StackUnderflowException {   .pdf
Q1. public void operationZ() throws StackUnderflowException {   .pdffatoryoutlets
 
Print Calculator Question 18 of 20 Sapling Learning Map do ment of Lu.pdf
Print Calculator Question 18 of 20 Sapling Learning Map do ment of Lu.pdfPrint Calculator Question 18 of 20 Sapling Learning Map do ment of Lu.pdf
Print Calculator Question 18 of 20 Sapling Learning Map do ment of Lu.pdffatoryoutlets
 
Part A 1. Solid product forms during the addition of the bleach solu.pdf
Part A 1. Solid product forms during the addition of the bleach solu.pdfPart A 1. Solid product forms during the addition of the bleach solu.pdf
Part A 1. Solid product forms during the addition of the bleach solu.pdffatoryoutlets
 
Only 15 of the carbon-14 in a wooden bowl remains. How old is the b.pdf
Only 15 of the carbon-14 in a wooden bowl remains. How old is the b.pdfOnly 15 of the carbon-14 in a wooden bowl remains. How old is the b.pdf
Only 15 of the carbon-14 in a wooden bowl remains. How old is the b.pdffatoryoutlets
 
Note Use Java Write a web server that is capable of processing only.pdf
Note Use Java Write a web server that is capable of processing only.pdfNote Use Java Write a web server that is capable of processing only.pdf
Note Use Java Write a web server that is capable of processing only.pdffatoryoutlets
 
Negotiations are not usually faster in Deal focused cultures than re.pdf
Negotiations are not usually faster in Deal focused cultures than re.pdfNegotiations are not usually faster in Deal focused cultures than re.pdf
Negotiations are not usually faster in Deal focused cultures than re.pdffatoryoutlets
 
9. The tort of assault and the tort of battery A) can occur independe.pdf
9. The tort of assault and the tort of battery A) can occur independe.pdf9. The tort of assault and the tort of battery A) can occur independe.pdf
9. The tort of assault and the tort of battery A) can occur independe.pdffatoryoutlets
 
Jj_numjnamecityj1SorterParisj2PunchRomej3Reade.pdf
Jj_numjnamecityj1SorterParisj2PunchRomej3Reade.pdfJj_numjnamecityj1SorterParisj2PunchRomej3Reade.pdf
Jj_numjnamecityj1SorterParisj2PunchRomej3Reade.pdffatoryoutlets
 
If law enforcement fails to give the defendant their Miranda rights,.pdf
If law enforcement fails to give the defendant their Miranda rights,.pdfIf law enforcement fails to give the defendant their Miranda rights,.pdf
If law enforcement fails to give the defendant their Miranda rights,.pdffatoryoutlets
 

More from fatoryoutlets (20)

Write an informal paper that is exactly 3 pages long not counting th.pdf
Write an informal paper that is exactly 3 pages long not counting th.pdfWrite an informal paper that is exactly 3 pages long not counting th.pdf
Write an informal paper that is exactly 3 pages long not counting th.pdf
 
Write a C program to find factorial of an integer n, where the user .pdf
Write a C program to find factorial of an integer n, where the user .pdfWrite a C program to find factorial of an integer n, where the user .pdf
Write a C program to find factorial of an integer n, where the user .pdf
 
When was the black body mutation in drosophila melanogaster discover.pdf
When was the black body mutation in drosophila melanogaster discover.pdfWhen was the black body mutation in drosophila melanogaster discover.pdf
When was the black body mutation in drosophila melanogaster discover.pdf
 
What is it that consumer researchers try to find among varying cultu.pdf
What is it that consumer researchers try to find among varying cultu.pdfWhat is it that consumer researchers try to find among varying cultu.pdf
What is it that consumer researchers try to find among varying cultu.pdf
 
What are pros and cons of Symantec endpoint security softwareSo.pdf
What are pros and cons of Symantec endpoint security softwareSo.pdfWhat are pros and cons of Symantec endpoint security softwareSo.pdf
What are pros and cons of Symantec endpoint security softwareSo.pdf
 
All of the following describe the International Accounting Standard .pdf
All of the following describe the International Accounting Standard .pdfAll of the following describe the International Accounting Standard .pdf
All of the following describe the International Accounting Standard .pdf
 
The right and left sternocleidomastoid muscles of humans originate o.pdf
The right and left sternocleidomastoid muscles of humans originate o.pdfThe right and left sternocleidomastoid muscles of humans originate o.pdf
The right and left sternocleidomastoid muscles of humans originate o.pdf
 
The code in image3.cpp has the error as shown above, could you help .pdf
The code in image3.cpp has the error as shown above, could you help .pdfThe code in image3.cpp has the error as shown above, could you help .pdf
The code in image3.cpp has the error as shown above, could you help .pdf
 
the ability of the cardiac muscle cells to fire on their own is .pdf
the ability of the cardiac muscle cells to fire on their own is .pdfthe ability of the cardiac muscle cells to fire on their own is .pdf
the ability of the cardiac muscle cells to fire on their own is .pdf
 
Surface water entering the North Atlantic may have a temperature of .pdf
Surface water entering the North Atlantic may have a temperature of .pdfSurface water entering the North Atlantic may have a temperature of .pdf
Surface water entering the North Atlantic may have a temperature of .pdf
 
Suppose the rate of plant growth on Isle Royale supported an equilib.pdf
Suppose the rate of plant growth on Isle Royale supported an equilib.pdfSuppose the rate of plant growth on Isle Royale supported an equilib.pdf
Suppose the rate of plant growth on Isle Royale supported an equilib.pdf
 
Q1. public void operationZ() throws StackUnderflowException {   .pdf
Q1. public void operationZ() throws StackUnderflowException {   .pdfQ1. public void operationZ() throws StackUnderflowException {   .pdf
Q1. public void operationZ() throws StackUnderflowException {   .pdf
 
Print Calculator Question 18 of 20 Sapling Learning Map do ment of Lu.pdf
Print Calculator Question 18 of 20 Sapling Learning Map do ment of Lu.pdfPrint Calculator Question 18 of 20 Sapling Learning Map do ment of Lu.pdf
Print Calculator Question 18 of 20 Sapling Learning Map do ment of Lu.pdf
 
Part A 1. Solid product forms during the addition of the bleach solu.pdf
Part A 1. Solid product forms during the addition of the bleach solu.pdfPart A 1. Solid product forms during the addition of the bleach solu.pdf
Part A 1. Solid product forms during the addition of the bleach solu.pdf
 
Only 15 of the carbon-14 in a wooden bowl remains. How old is the b.pdf
Only 15 of the carbon-14 in a wooden bowl remains. How old is the b.pdfOnly 15 of the carbon-14 in a wooden bowl remains. How old is the b.pdf
Only 15 of the carbon-14 in a wooden bowl remains. How old is the b.pdf
 
Note Use Java Write a web server that is capable of processing only.pdf
Note Use Java Write a web server that is capable of processing only.pdfNote Use Java Write a web server that is capable of processing only.pdf
Note Use Java Write a web server that is capable of processing only.pdf
 
Negotiations are not usually faster in Deal focused cultures than re.pdf
Negotiations are not usually faster in Deal focused cultures than re.pdfNegotiations are not usually faster in Deal focused cultures than re.pdf
Negotiations are not usually faster in Deal focused cultures than re.pdf
 
9. The tort of assault and the tort of battery A) can occur independe.pdf
9. The tort of assault and the tort of battery A) can occur independe.pdf9. The tort of assault and the tort of battery A) can occur independe.pdf
9. The tort of assault and the tort of battery A) can occur independe.pdf
 
Jj_numjnamecityj1SorterParisj2PunchRomej3Reade.pdf
Jj_numjnamecityj1SorterParisj2PunchRomej3Reade.pdfJj_numjnamecityj1SorterParisj2PunchRomej3Reade.pdf
Jj_numjnamecityj1SorterParisj2PunchRomej3Reade.pdf
 
If law enforcement fails to give the defendant their Miranda rights,.pdf
If law enforcement fails to give the defendant their Miranda rights,.pdfIf law enforcement fails to give the defendant their Miranda rights,.pdf
If law enforcement fails to give the defendant their Miranda rights,.pdf
 

Recently uploaded

18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdfssuser54595a
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Sapana Sha
 
Painted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of IndiaPainted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of IndiaVirag Sontakke
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Educationpboyjonauth
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentInMediaRes1
 
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Celine George
 
Biting mechanism of poisonous snakes.pdf
Biting mechanism of poisonous snakes.pdfBiting mechanism of poisonous snakes.pdf
Biting mechanism of poisonous snakes.pdfadityarao40181
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxGaneshChakor2
 
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfEnzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfSumit Tiwari
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformChameera Dedduwage
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxmanuelaromero2013
 
How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17Celine George
 
EPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptxEPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptxRaymartEstabillo3
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionSafetyChain Software
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)eniolaolutunde
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxOH TEIK BIN
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptxVS Mahajan Coaching Centre
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxNirmalaLoungPoorunde1
 

Recently uploaded (20)

18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
 
Painted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of IndiaPainted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of India
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Education
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media Component
 
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
 
Biting mechanism of poisonous snakes.pdf
Biting mechanism of poisonous snakes.pdfBiting mechanism of poisonous snakes.pdf
Biting mechanism of poisonous snakes.pdf
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptx
 
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdfTataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
 
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfEnzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
 
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy Reform
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptx
 
How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17
 
EPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptxEPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptx
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory Inspection
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptx
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptx
 

Template LinkedList;I am using templates to make some linkedLists.pdf

  • 1. Template LinkedList; I am using templates to make some linkedLists Here is the Data and next pointer class: and here is my header where i do the implementations, aswell as an explanation as to what the functions should do Can anybody please help me with the implementations so i can get a better understanding? Thankyou very much in advance! (If possible please answer from a computer :D) 1 #pragma once 1 3 template typename T 4 E class Node public 7 I ode( T(), Node Solution LLToolkit.h #ifndef LLTOOLKIT_H_ #define LLTOOLKIT_H_ #include #include "Node.h" using namespace std; template class LLToolkit { public: // Precondition: headPtr points to the head of a list // Postcondition: Info has been inserted at the head of the list, and headPtr is updated void headInsert(Node*& headPtr, T data) { headPtr = new Node(data, headPtr); } // Precondition: headPtr points to the head of a list with at least 1 element // Postcondition: The head element has been removed and headPtr is updated to point to the new // head element void headRemove(Node*& headPtr) { if (headPtr != NULL)
  • 2. { Node* condemned = headPtr; headPtr = headPtr->next; delete condemned; } } // Precondition: prevPtr points to Node just before insertion point // Postcondition: A new Node with data=info has been inserted into the list after prevPtr void insert(Node*& prevPtr, T data) { if (prevPtr == NULL) return; Node* next = prevPtr->next; prevPtr->next = new Node(data, next); } // Precondition: prevPtr points to Node just before Node to remove // Postcondition: The Node after prevPtr has been removed from the list void remove(Node*& prevPtr) { if (prevPtr == NULL) return; if (prevPtr->next == NULL) return; Node* condemned = prevPtr->next; prevPtr->next = condemned->next; delete prevPtr->next; } // Precondition: sourcePtr is the head pointer of a linked list. // Postcondition: A pointer to a copy of the linked list is returned. The original list is // unaltered. Node* copy(Node* sourcePtr) { Node* headPtr = NULL; // Head pointer for new list Node* tailPtr = NULL; // Handle the case of the empty list. if (sourcePtr == NULL) return headPtr;
  • 3. // Make the head LLNode for the newly created list, and put data in it. headInsert(headPtr, sourcePtr->info); tailPtr = headPtr; // Copy the rest of the nodes one at a time, adding at the tail of new list. sourcePtr = sourcePtr->next; while (sourcePtr != NULL) { insert(tailPtr, sourcePtr->info); tailPtr = tailPtr->next; sourcePtr = sourcePtr->next; } return headPtr; } // Precondition: headPtr is the head pointer of a linked list. // Postcondition: All nodes of the list have been deleted, and the headPtr is NULL. void clear(Node* headPtr) { while (headPtr != NULL) { Node* prevPtr = headPtr; headPtr = headPtr->next; delete prevPtr; } return headPtr; } // Precondition: headPtr is the head pointer of a linked list. // Postcondition: The data item of each Node in the list has been printed to the screen in an // easily readable way, e.g. 3 - 4 - 7 -/ void print(Node* headPtr) { while (headPtr != NULL) { cout << headPtr->info << endl; headPtr = headPtr->next; } }
  • 4. // Precondition: headPtr is the head pointer of a linked list. // Postcondition: headPtr points to the start of a list that is reversed with respect to the // original list void reverse(Node*& headPtr) { Node* tempPtr = NULL; // Head pointer for new list // Handle the case of the empty list. if (headPtr == NULL) { cout << "Can't reverse an empty list" << endl; return; } // Copy the rest of the nodes one at a time, adding at the tail of new list. while (headPtr != NULL) { headInsert(tempPtr, headPtr->info); headPtr = headPtr->next; } headPtr = tempPtr; } // Precondition: splitPtr points to the node before the split point // Postcondition: A pointer is returned that points to the first node after splitPtr. The // original list ends at the node pointed to by splitPtr Node* split(Node* splitPtr) { Node* newHeadPtr = splitPtr->next; splitPtr->next = NULL; return newHeadPtr; } // Precondition: values points to an array of at least size n // Postcondition: A pointer is returned that points to the head of a list in which the nodes // contains values from the array values Node* build(int* values, size_t n) { Node* headPtr = NULL; // Head pointer for new list Node* tailPtr = NULL;
  • 5. // Make the head LLNode for the newly created list, and put data in it. headInsert(headPtr, values[0]); tailPtr = headPtr; for (int i = 1; i < n; i++) { insert(tailPtr, values[i]); tailPtr = tailPtr->next; } return headPtr; } // Precondition: head1 and head2 each point to the head of linked lists // Postcondition: head1 points to a list containing head1-lists' elements followed by head2- lists // element. void join(Node* head1, Node* head2) { Node *tailPtr; //krer en lkke for at finde sidste plads //i head1 s listerne kan sttes sammen. while (head1 != NULL) { tailPtr = head1; head1 = head1->next; } //TailPtr bliver nu brugt til at stte de lister sammen tailPtr->next = head2; } // Precondition: head points to the head of a linked list // Postcondition: The list is rotated left by once - if it was 1-2-3-4, it is now 2-3-4-1 void rotateLeft(Node*& headPtr) { Node *tailPtr; Node *tempPtr = headPtr; //krer en lkke for at finde sidste vrdi i listen while (tempPtr != NULL) {
  • 6. tailPtr = tempPtr; tempPtr = tempPtr->next; } insert(tailPtr, headPtr->info); headPtr = headPtr->next; } // Precondition: head points to the head of a linked list // Postcondition: The list is rotated right once - if it was 1-2-3-4, it is now 4-1-2-3 void rotateRight(Node*& head) { Node *tailPtr; Node *tempPtr = head; //en while lkke til at finde den sidste vrdi i den linkede liste while (tempPtr->next != NULL) { tailPtr = tempPtr; tempPtr = tempPtr->next; } headInsert(head, tempPtr->info); tailPtr->next = NULL; delete tempPtr; } }; #endif // LLTOOLKIT_H_ Node.h #ifndef NODE_H_ #define NODE_H_ #include template class Node { public: Node(const T& i = T(), Node* n = NULL) : info(i), next(n)