SlideShare a Scribd company logo
For this micro assignment, you must implement two Linked List
functions. We will use the following
example Linked List:
2 0 -1 5 7
getElementAt(index)
This function should return the element (i.e. value) of the Nth
item inside the linked list. For example,
on the Linked List above, getElementAt(0) should return 2;
getElementAt(3) should return 5.
addElementAt(value, location)
This function should insert a new value at the given location.
Note that the location supplied must be
within bounds of the LinkedList. For example, we cannot call
addElementAt(4, 11) on the above Linked
List because 11 is beyond the size of the Linked List.
Here are some examples. If we call addElementAt(0, 1), the
above Linked List would now look like:
1 2 0 -1 5 7
If we again call addElementAt(2, 123), we would get:
1 2 123 0 -1 5
7
Grading
Your submission will be graded based on the following:
1. [7] Your solution does not cause any runtime issues and your
file passes all test cases
2. [3] Your code contains good style. For example,
ble names
@@@@@@@@@@@@@@@@@@@@@@@@
#ifndef LINKED_LIST_H
#define LINKED_LIST_H
#include
#include
#include "LinkedListNode.h"
#include
using namespace std;
template
class LinkedList
{
private:
//points to the front of the linked list
LinkedListNode *_front = nullptr;
//keeping track of size in a variable eliminates need to
continually
//count LL boxes.
int _size = 0;
protected:
//creates a new LinkedListNode for us
virtual LinkedListNode *createNode(T value)
{
return new LinkedListNode < T > { value };
}
public:
//default constructor
LinkedList()
{
_front = nullptr;
}
//copy constructor
LinkedList(const LinkedList &other)
{
for (int i = 0; i < other.getSize(); i++)
{
addElement(other.getElementAt(i));
}
}
//move constructor
LinkedList(LinkedList &&other)
{
//take other's data
_front = other._front;
_size = other._size;
//reset other's pointers
other._front = nullptr;
}
//initializer list constructor
LinkedList(initializer_list values)
{
for (auto item : values)
{
addElement(item);
}
}
//Always remember to clean up pointers in destructor!
virtual ~LinkedList()
{
LinkedListNode *current = _front;
while (current != nullptr)
{
LinkedListNode *temp = current->getNext();
delete current;
current = temp;
}
}
//will return true if the LL is empty.
virtual bool isEmpty() const
{
return _size == 0;
}
//returns the size of the LL.
virtual int getSize() const
{
return _size;
}
//adds the supplied item to the end of our LL
virtual void addElement(T value)
{
addElementAt(value, getSize());
}
//Returns the value of the LinkedListNode at the given index
virtual T& getElementAt(int index)
{
//MA #1 TODO: ACTUALLY IMPLEMENT!
**************** add here
int value = -1;
return value;
}
//adds the specified item at the specified index and shifts
everything else
//to the "right" by one.
virtual void addElementAt(T value, int location)
{
LinkedListNode *new_value = createNode(value);
//MA #1 TODO: IMPLEMENT! ************** and
here
// Add variable new_value to proper location inside
// our linked list.
}
};
#endif // !LINKED_LIST_H
@@@@@@@@@@@@@@@@@@@@@@@
#ifndef LINKED_LIST_NODE_H
#define LINKED_LIST_NODE_H
//A linked list node represents a single "box" inside a lined list.
In this
//scheme, the LinkedList is simply a collection of
LinkedListNode boxes.
template
class LinkedListNode
{
protected:
//value that our box contains
T _value;
//pointer to next node in the LL sequence
LinkedListNode *_next;
public:
//constructor must accept a default value
LinkedListNode(const T &value) : _value(value)
{
_next = nullptr;
}
LinkedListNode()
{
_next = nullptr;
}
//copy constructor prevents premature deletion of next
pointer
LinkedListNode(const LinkedListNode &other)
{
_value = other.getValue();
_next = other.getNext();
}
virtual ~LinkedListNode()
{
}
//copy operator allows us to reassign previously created
list nodes
LinkedListNode &operator=(const LinkedListNode
&other)
{
if (this != &other)
{
LinkedListNode temp(other);
swap(*this, temp);
}
return *this;
}
//returns a pointer to the next list node in the sequence
LinkedListNode *getNext()
{
return _next;
}
//sets the pointer to the next node in the sequence
void setNext(LinkedListNode *next)
{
_next = next;
}
//returns the value of the list node
T &getValue()
{
return _value;
}
//constant version of the getter
const T& getValue() const
{
return _value;
}
//sets the value of the current list node
void setValue(const T &value)
{
_value = value;
}
};
#endif
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@
#include
#include
#include "LinkedList.h"
using namespace std;
void linkedListTest()
{
cout << "***Linked List Test***" << endl;
LinkedList test_list{};
test_list.addElementAt(0, 1);
test_list.addElementAt(1, 2);
test_list.addElementAt(0, 3);
test_list.addElementAt(2, 4);
cout << "Number of elements in LL: " << test_list.getSize()
<< " (expected: 4)" << endl;
cout << "Value at 0: " << test_list.getElementAt(0) << "
(expected: 3)" << endl;
cout << "Value at 1: " << test_list.getElementAt(1) << "
(expected: 1)" << endl;
cout << "Value at 2: " << test_list.getElementAt(2) << "
(expected: 4)" << endl;
cout << "Value at 3: " << test_list.getElementAt(3) << "
(expected: 2)" << endl;
}
int main()
{
linkedListTest();
}

More Related Content

Similar to For this micro assignment, you must implement two Linked List functi.docx

To complete the task, you need to fill in the missing code. I’ve inc.pdf
To complete the task, you need to fill in the missing code. I’ve inc.pdfTo complete the task, you need to fill in the missing code. I’ve inc.pdf
To complete the task, you need to fill in the missing code. I’ve inc.pdf
ezycolours78
 
How do I fix it in LinkedList.javathis is what i didLabProgra.pdf
How do I fix it in LinkedList.javathis is what i didLabProgra.pdfHow do I fix it in LinkedList.javathis is what i didLabProgra.pdf
How do I fix it in LinkedList.javathis is what i didLabProgra.pdf
mail931892
 
Given below is the completed implementation of MyLinkedList class. O.pdf
Given below is the completed implementation of MyLinkedList class. O.pdfGiven below is the completed implementation of MyLinkedList class. O.pdf
Given below is the completed implementation of MyLinkedList class. O.pdf
info430661
 
Hi,I have added the methods and main class as per your requirement.pdf
Hi,I have added the methods and main class as per your requirement.pdfHi,I have added the methods and main class as per your requirement.pdf
Hi,I have added the methods and main class as per your requirement.pdf
annaelctronics
 
Consider a double-linked linked list implementation with the followin.pdf
Consider a double-linked linked list implementation with the followin.pdfConsider a double-linked linked list implementation with the followin.pdf
Consider a double-linked linked list implementation with the followin.pdf
sales98
 
This is problem is same problem which i submitted on 22017, I just.pdf
This is problem is same problem which i submitted on 22017, I just.pdfThis is problem is same problem which i submitted on 22017, I just.pdf
This is problem is same problem which i submitted on 22017, I just.pdf
fcaindore
 
How do you stop infinite loop Because I believe that it is making a.pdf
How do you stop infinite loop Because I believe that it is making a.pdfHow do you stop infinite loop Because I believe that it is making a.pdf
How do you stop infinite loop Because I believe that it is making a.pdf
feelinggift
 
hi i have to write a java program involving link lists. i have a pro.pdf
hi i have to write a java program involving link lists. i have a pro.pdfhi i have to write a java program involving link lists. i have a pro.pdf
hi i have to write a java program involving link lists. i have a pro.pdf
archgeetsenterprises
 
Inspect the class declaration for a doubly-linked list node in Node-h-.pdf
Inspect the class declaration for a doubly-linked list node in Node-h-.pdfInspect the class declaration for a doubly-linked list node in Node-h-.pdf
Inspect the class declaration for a doubly-linked list node in Node-h-.pdf
vishalateen
 
Lab-2.4 101.pdf
Lab-2.4 101.pdfLab-2.4 101.pdf
Lab-2.4 101.pdf
21E135MAHIESHWARJ
 
Copy your completed LinkedList class from Lab 3 into the LinkedList..pdf
Copy your completed LinkedList class from Lab 3 into the LinkedList..pdfCopy your completed LinkedList class from Lab 3 into the LinkedList..pdf
Copy your completed LinkedList class from Lab 3 into the LinkedList..pdf
facevenky
 
STAGE 2 The Methods 65 points Implement all the methods t.pdf
STAGE 2 The Methods 65 points Implement all the methods t.pdfSTAGE 2 The Methods 65 points Implement all the methods t.pdf
STAGE 2 The Methods 65 points Implement all the methods t.pdf
babitasingh698417
 
public class MyLinkedListltE extends ComparableltEgtg.pdf
public class MyLinkedListltE extends ComparableltEgtg.pdfpublic class MyLinkedListltE extends ComparableltEgtg.pdf
public class MyLinkedListltE extends ComparableltEgtg.pdf
accostinternational
 
Data Structures in C++I am really new to C++, so links are really .pdf
Data Structures in C++I am really new to C++, so links are really .pdfData Structures in C++I am really new to C++, so links are really .pdf
Data Structures in C++I am really new to C++, so links are really .pdf
rohit219406
 
Labprogram.javaLinkedList.javaimport java.util.NoSuchElementEx.pdf
Labprogram.javaLinkedList.javaimport java.util.NoSuchElementEx.pdfLabprogram.javaLinkedList.javaimport java.util.NoSuchElementEx.pdf
Labprogram.javaLinkedList.javaimport java.util.NoSuchElementEx.pdf
freddysarabia1
 
In C++ please, do not alter node.hStep 1 Inspect the Node.h file.pdf
In C++ please, do not alter node.hStep 1 Inspect the Node.h file.pdfIn C++ please, do not alter node.hStep 1 Inspect the Node.h file.pdf
In C++ please, do not alter node.hStep 1 Inspect the Node.h file.pdf
stopgolook
 
Write a function to merge two doubly linked lists. The input lists ha.pdf
Write a function to merge two doubly linked lists. The input lists ha.pdfWrite a function to merge two doubly linked lists. The input lists ha.pdf
Write a function to merge two doubly linked lists. The input lists ha.pdf
info706022
 
File LinkedList.java Defines a doubly-l.pdf
File LinkedList.java Defines a doubly-l.pdfFile LinkedList.java Defines a doubly-l.pdf
File LinkedList.java Defines a doubly-l.pdf
Conint29
 
Data Structures and Agorithm: DS 05 Doubly Linked List.pptx
Data Structures and Agorithm: DS 05 Doubly Linked List.pptxData Structures and Agorithm: DS 05 Doubly Linked List.pptx
Data Structures and Agorithm: DS 05 Doubly Linked List.pptx
RashidFaridChishti
 
Need done for Date Structures please! 4-18 LAB- Sorted number list imp.pdf
Need done for Date Structures please! 4-18 LAB- Sorted number list imp.pdfNeed done for Date Structures please! 4-18 LAB- Sorted number list imp.pdf
Need done for Date Structures please! 4-18 LAB- Sorted number list imp.pdf
info114
 

Similar to For this micro assignment, you must implement two Linked List functi.docx (20)

To complete the task, you need to fill in the missing code. I’ve inc.pdf
To complete the task, you need to fill in the missing code. I’ve inc.pdfTo complete the task, you need to fill in the missing code. I’ve inc.pdf
To complete the task, you need to fill in the missing code. I’ve inc.pdf
 
How do I fix it in LinkedList.javathis is what i didLabProgra.pdf
How do I fix it in LinkedList.javathis is what i didLabProgra.pdfHow do I fix it in LinkedList.javathis is what i didLabProgra.pdf
How do I fix it in LinkedList.javathis is what i didLabProgra.pdf
 
Given below is the completed implementation of MyLinkedList class. O.pdf
Given below is the completed implementation of MyLinkedList class. O.pdfGiven below is the completed implementation of MyLinkedList class. O.pdf
Given below is the completed implementation of MyLinkedList class. O.pdf
 
Hi,I have added the methods and main class as per your requirement.pdf
Hi,I have added the methods and main class as per your requirement.pdfHi,I have added the methods and main class as per your requirement.pdf
Hi,I have added the methods and main class as per your requirement.pdf
 
Consider a double-linked linked list implementation with the followin.pdf
Consider a double-linked linked list implementation with the followin.pdfConsider a double-linked linked list implementation with the followin.pdf
Consider a double-linked linked list implementation with the followin.pdf
 
This is problem is same problem which i submitted on 22017, I just.pdf
This is problem is same problem which i submitted on 22017, I just.pdfThis is problem is same problem which i submitted on 22017, I just.pdf
This is problem is same problem which i submitted on 22017, I just.pdf
 
How do you stop infinite loop Because I believe that it is making a.pdf
How do you stop infinite loop Because I believe that it is making a.pdfHow do you stop infinite loop Because I believe that it is making a.pdf
How do you stop infinite loop Because I believe that it is making a.pdf
 
hi i have to write a java program involving link lists. i have a pro.pdf
hi i have to write a java program involving link lists. i have a pro.pdfhi i have to write a java program involving link lists. i have a pro.pdf
hi i have to write a java program involving link lists. i have a pro.pdf
 
Inspect the class declaration for a doubly-linked list node in Node-h-.pdf
Inspect the class declaration for a doubly-linked list node in Node-h-.pdfInspect the class declaration for a doubly-linked list node in Node-h-.pdf
Inspect the class declaration for a doubly-linked list node in Node-h-.pdf
 
Lab-2.4 101.pdf
Lab-2.4 101.pdfLab-2.4 101.pdf
Lab-2.4 101.pdf
 
Copy your completed LinkedList class from Lab 3 into the LinkedList..pdf
Copy your completed LinkedList class from Lab 3 into the LinkedList..pdfCopy your completed LinkedList class from Lab 3 into the LinkedList..pdf
Copy your completed LinkedList class from Lab 3 into the LinkedList..pdf
 
STAGE 2 The Methods 65 points Implement all the methods t.pdf
STAGE 2 The Methods 65 points Implement all the methods t.pdfSTAGE 2 The Methods 65 points Implement all the methods t.pdf
STAGE 2 The Methods 65 points Implement all the methods t.pdf
 
public class MyLinkedListltE extends ComparableltEgtg.pdf
public class MyLinkedListltE extends ComparableltEgtg.pdfpublic class MyLinkedListltE extends ComparableltEgtg.pdf
public class MyLinkedListltE extends ComparableltEgtg.pdf
 
Data Structures in C++I am really new to C++, so links are really .pdf
Data Structures in C++I am really new to C++, so links are really .pdfData Structures in C++I am really new to C++, so links are really .pdf
Data Structures in C++I am really new to C++, so links are really .pdf
 
Labprogram.javaLinkedList.javaimport java.util.NoSuchElementEx.pdf
Labprogram.javaLinkedList.javaimport java.util.NoSuchElementEx.pdfLabprogram.javaLinkedList.javaimport java.util.NoSuchElementEx.pdf
Labprogram.javaLinkedList.javaimport java.util.NoSuchElementEx.pdf
 
In C++ please, do not alter node.hStep 1 Inspect the Node.h file.pdf
In C++ please, do not alter node.hStep 1 Inspect the Node.h file.pdfIn C++ please, do not alter node.hStep 1 Inspect the Node.h file.pdf
In C++ please, do not alter node.hStep 1 Inspect the Node.h file.pdf
 
Write a function to merge two doubly linked lists. The input lists ha.pdf
Write a function to merge two doubly linked lists. The input lists ha.pdfWrite a function to merge two doubly linked lists. The input lists ha.pdf
Write a function to merge two doubly linked lists. The input lists ha.pdf
 
File LinkedList.java Defines a doubly-l.pdf
File LinkedList.java Defines a doubly-l.pdfFile LinkedList.java Defines a doubly-l.pdf
File LinkedList.java Defines a doubly-l.pdf
 
Data Structures and Agorithm: DS 05 Doubly Linked List.pptx
Data Structures and Agorithm: DS 05 Doubly Linked List.pptxData Structures and Agorithm: DS 05 Doubly Linked List.pptx
Data Structures and Agorithm: DS 05 Doubly Linked List.pptx
 
Need done for Date Structures please! 4-18 LAB- Sorted number list imp.pdf
Need done for Date Structures please! 4-18 LAB- Sorted number list imp.pdfNeed done for Date Structures please! 4-18 LAB- Sorted number list imp.pdf
Need done for Date Structures please! 4-18 LAB- Sorted number list imp.pdf
 

More from mckellarhastings

Conduct an internet search finding a job you are interested (HR .docx
Conduct an internet search finding a job you are interested (HR .docxConduct an internet search finding a job you are interested (HR .docx
Conduct an internet search finding a job you are interested (HR .docx
mckellarhastings
 
Conduct an Internet or library search for information on The Bay of.docx
Conduct an Internet or library search for information on The Bay of.docxConduct an Internet or library search for information on The Bay of.docx
Conduct an Internet or library search for information on The Bay of.docx
mckellarhastings
 
Conduct an internet search about the murder of Yeardley Love. After .docx
Conduct an internet search about the murder of Yeardley Love. After .docxConduct an internet search about the murder of Yeardley Love. After .docx
Conduct an internet search about the murder of Yeardley Love. After .docx
mckellarhastings
 
At this point, you’ve organized your HR project team and you are.docx
At this point, you’ve organized your HR project team and you are.docxAt this point, you’ve organized your HR project team and you are.docx
At this point, you’ve organized your HR project team and you are.docx
mckellarhastings
 
At the beginning of 2012, the Jeater company had the following balan.docx
At the beginning of 2012, the Jeater company had the following balan.docxAt the beginning of 2012, the Jeater company had the following balan.docx
At the beginning of 2012, the Jeater company had the following balan.docx
mckellarhastings
 
At many different points throughout the collection Born a Crime, Tre.docx
At many different points throughout the collection Born a Crime, Tre.docxAt many different points throughout the collection Born a Crime, Tre.docx
At many different points throughout the collection Born a Crime, Tre.docx
mckellarhastings
 
At least 200 wordss or more per question. Answer UNDER question. And.docx
At least 200 wordss or more per question. Answer UNDER question. And.docxAt least 200 wordss or more per question. Answer UNDER question. And.docx
At least 200 wordss or more per question. Answer UNDER question. And.docx
mckellarhastings
 
At least 200 words per question. Chapter 11The Idea .docx
At least 200 words per question. Chapter 11The Idea .docxAt least 200 words per question. Chapter 11The Idea .docx
At least 200 words per question. Chapter 11The Idea .docx
mckellarhastings
 
At least 150 words each. Use a reference for each question and us.docx
At least 150 words each.  Use a reference for each question and us.docxAt least 150 words each.  Use a reference for each question and us.docx
At least 150 words each. Use a reference for each question and us.docx
mckellarhastings
 
At least 250 words per question. Chapter 11The Idea of Craft A.docx
At least 250 words per question. Chapter 11The Idea of Craft A.docxAt least 250 words per question. Chapter 11The Idea of Craft A.docx
At least 250 words per question. Chapter 11The Idea of Craft A.docx
mckellarhastings
 
At its core, pathology is the study of disease. Diseases occur for m.docx
At its core, pathology is the study of disease. Diseases occur for m.docxAt its core, pathology is the study of disease. Diseases occur for m.docx
At its core, pathology is the study of disease. Diseases occur for m.docx
mckellarhastings
 
assumptions people make about this topic (homelessness, immigration,.docx
assumptions people make about this topic (homelessness, immigration,.docxassumptions people make about this topic (homelessness, immigration,.docx
assumptions people make about this topic (homelessness, immigration,.docx
mckellarhastings
 
At age 12, Freeman Hrabowski marched with Martin Luther King. Now he.docx
At age 12, Freeman Hrabowski marched with Martin Luther King. Now he.docxAt age 12, Freeman Hrabowski marched with Martin Luther King. Now he.docx
At age 12, Freeman Hrabowski marched with Martin Luther King. Now he.docx
mckellarhastings
 
At each of the locations listed below, there is evidence of plat.docx
At each of the locations listed below, there is evidence of plat.docxAt each of the locations listed below, there is evidence of plat.docx
At each of the locations listed below, there is evidence of plat.docx
mckellarhastings
 
Assume you hold the Special Agent in Charge role of the Joint .docx
Assume you hold the Special Agent in Charge role of the Joint .docxAssume you hold the Special Agent in Charge role of the Joint .docx
Assume you hold the Special Agent in Charge role of the Joint .docx
mckellarhastings
 
Assume you are a DFI and you must deliver a presentation to the Stat.docx
Assume you are a DFI and you must deliver a presentation to the Stat.docxAssume you are a DFI and you must deliver a presentation to the Stat.docx
Assume you are a DFI and you must deliver a presentation to the Stat.docx
mckellarhastings
 
Assume that you work for the District Board of Education. The Direct.docx
Assume that you work for the District Board of Education. The Direct.docxAssume that you work for the District Board of Education. The Direct.docx
Assume that you work for the District Board of Education. The Direct.docx
mckellarhastings
 
Assume that you have been tasked by your employer to develop an inci.docx
Assume that you have been tasked by your employer to develop an inci.docxAssume that you have been tasked by your employer to develop an inci.docx
Assume that you have been tasked by your employer to develop an inci.docx
mckellarhastings
 
Assume that you generate an authenticated and encrypted message by f.docx
Assume that you generate an authenticated and encrypted message by f.docxAssume that you generate an authenticated and encrypted message by f.docx
Assume that you generate an authenticated and encrypted message by f.docx
mckellarhastings
 
Assume that you are in your chosen criminal justice profession, .docx
Assume that you are in your chosen criminal justice profession, .docxAssume that you are in your chosen criminal justice profession, .docx
Assume that you are in your chosen criminal justice profession, .docx
mckellarhastings
 

More from mckellarhastings (20)

Conduct an internet search finding a job you are interested (HR .docx
Conduct an internet search finding a job you are interested (HR .docxConduct an internet search finding a job you are interested (HR .docx
Conduct an internet search finding a job you are interested (HR .docx
 
Conduct an Internet or library search for information on The Bay of.docx
Conduct an Internet or library search for information on The Bay of.docxConduct an Internet or library search for information on The Bay of.docx
Conduct an Internet or library search for information on The Bay of.docx
 
Conduct an internet search about the murder of Yeardley Love. After .docx
Conduct an internet search about the murder of Yeardley Love. After .docxConduct an internet search about the murder of Yeardley Love. After .docx
Conduct an internet search about the murder of Yeardley Love. After .docx
 
At this point, you’ve organized your HR project team and you are.docx
At this point, you’ve organized your HR project team and you are.docxAt this point, you’ve organized your HR project team and you are.docx
At this point, you’ve organized your HR project team and you are.docx
 
At the beginning of 2012, the Jeater company had the following balan.docx
At the beginning of 2012, the Jeater company had the following balan.docxAt the beginning of 2012, the Jeater company had the following balan.docx
At the beginning of 2012, the Jeater company had the following balan.docx
 
At many different points throughout the collection Born a Crime, Tre.docx
At many different points throughout the collection Born a Crime, Tre.docxAt many different points throughout the collection Born a Crime, Tre.docx
At many different points throughout the collection Born a Crime, Tre.docx
 
At least 200 wordss or more per question. Answer UNDER question. And.docx
At least 200 wordss or more per question. Answer UNDER question. And.docxAt least 200 wordss or more per question. Answer UNDER question. And.docx
At least 200 wordss or more per question. Answer UNDER question. And.docx
 
At least 200 words per question. Chapter 11The Idea .docx
At least 200 words per question. Chapter 11The Idea .docxAt least 200 words per question. Chapter 11The Idea .docx
At least 200 words per question. Chapter 11The Idea .docx
 
At least 150 words each. Use a reference for each question and us.docx
At least 150 words each.  Use a reference for each question and us.docxAt least 150 words each.  Use a reference for each question and us.docx
At least 150 words each. Use a reference for each question and us.docx
 
At least 250 words per question. Chapter 11The Idea of Craft A.docx
At least 250 words per question. Chapter 11The Idea of Craft A.docxAt least 250 words per question. Chapter 11The Idea of Craft A.docx
At least 250 words per question. Chapter 11The Idea of Craft A.docx
 
At its core, pathology is the study of disease. Diseases occur for m.docx
At its core, pathology is the study of disease. Diseases occur for m.docxAt its core, pathology is the study of disease. Diseases occur for m.docx
At its core, pathology is the study of disease. Diseases occur for m.docx
 
assumptions people make about this topic (homelessness, immigration,.docx
assumptions people make about this topic (homelessness, immigration,.docxassumptions people make about this topic (homelessness, immigration,.docx
assumptions people make about this topic (homelessness, immigration,.docx
 
At age 12, Freeman Hrabowski marched with Martin Luther King. Now he.docx
At age 12, Freeman Hrabowski marched with Martin Luther King. Now he.docxAt age 12, Freeman Hrabowski marched with Martin Luther King. Now he.docx
At age 12, Freeman Hrabowski marched with Martin Luther King. Now he.docx
 
At each of the locations listed below, there is evidence of plat.docx
At each of the locations listed below, there is evidence of plat.docxAt each of the locations listed below, there is evidence of plat.docx
At each of the locations listed below, there is evidence of plat.docx
 
Assume you hold the Special Agent in Charge role of the Joint .docx
Assume you hold the Special Agent in Charge role of the Joint .docxAssume you hold the Special Agent in Charge role of the Joint .docx
Assume you hold the Special Agent in Charge role of the Joint .docx
 
Assume you are a DFI and you must deliver a presentation to the Stat.docx
Assume you are a DFI and you must deliver a presentation to the Stat.docxAssume you are a DFI and you must deliver a presentation to the Stat.docx
Assume you are a DFI and you must deliver a presentation to the Stat.docx
 
Assume that you work for the District Board of Education. The Direct.docx
Assume that you work for the District Board of Education. The Direct.docxAssume that you work for the District Board of Education. The Direct.docx
Assume that you work for the District Board of Education. The Direct.docx
 
Assume that you have been tasked by your employer to develop an inci.docx
Assume that you have been tasked by your employer to develop an inci.docxAssume that you have been tasked by your employer to develop an inci.docx
Assume that you have been tasked by your employer to develop an inci.docx
 
Assume that you generate an authenticated and encrypted message by f.docx
Assume that you generate an authenticated and encrypted message by f.docxAssume that you generate an authenticated and encrypted message by f.docx
Assume that you generate an authenticated and encrypted message by f.docx
 
Assume that you are in your chosen criminal justice profession, .docx
Assume that you are in your chosen criminal justice profession, .docxAssume that you are in your chosen criminal justice profession, .docx
Assume that you are in your chosen criminal justice profession, .docx
 

Recently uploaded

PIMS Job Advertisement 2024.pdf Islamabad
PIMS Job Advertisement 2024.pdf IslamabadPIMS Job Advertisement 2024.pdf Islamabad
PIMS Job Advertisement 2024.pdf Islamabad
AyyanKhan40
 
How to Fix the Import Error in the Odoo 17
How to Fix the Import Error in the Odoo 17How to Fix the Import Error in the Odoo 17
How to Fix the Import Error in the Odoo 17
Celine George
 
How to Setup Warehouse & Location in Odoo 17 Inventory
How to Setup Warehouse & Location in Odoo 17 InventoryHow to Setup Warehouse & Location in Odoo 17 Inventory
How to Setup Warehouse & Location in Odoo 17 Inventory
Celine George
 
PCOS corelations and management through Ayurveda.
PCOS corelations and management through Ayurveda.PCOS corelations and management through Ayurveda.
PCOS corelations and management through Ayurveda.
Dr. Shivangi Singh Parihar
 
Film vocab for eal 3 students: Australia the movie
Film vocab for eal 3 students: Australia the movieFilm vocab for eal 3 students: Australia the movie
Film vocab for eal 3 students: Australia the movie
Nicholas Montgomery
 
Pride Month Slides 2024 David Douglas School District
Pride Month Slides 2024 David Douglas School DistrictPride Month Slides 2024 David Douglas School District
Pride Month Slides 2024 David Douglas School District
David Douglas School District
 
Azure Interview Questions and Answers PDF By ScholarHat
Azure Interview Questions and Answers PDF By ScholarHatAzure Interview Questions and Answers PDF By ScholarHat
Azure Interview Questions and Answers PDF By ScholarHat
Scholarhat
 
ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...
ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...
ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...
PECB
 
Advanced Java[Extra Concepts, Not Difficult].docx
Advanced Java[Extra Concepts, Not Difficult].docxAdvanced Java[Extra Concepts, Not Difficult].docx
Advanced Java[Extra Concepts, Not Difficult].docx
adhitya5119
 
The basics of sentences session 6pptx.pptx
The basics of sentences session 6pptx.pptxThe basics of sentences session 6pptx.pptx
The basics of sentences session 6pptx.pptx
heathfieldcps1
 
বাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdf
বাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdfবাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdf
বাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdf
eBook.com.bd (প্রয়োজনীয় বাংলা বই)
 
BBR 2024 Summer Sessions Interview Training
BBR  2024 Summer Sessions Interview TrainingBBR  2024 Summer Sessions Interview Training
BBR 2024 Summer Sessions Interview Training
Katrina Pritchard
 
ANATOMY AND BIOMECHANICS OF HIP JOINT.pdf
ANATOMY AND BIOMECHANICS OF HIP JOINT.pdfANATOMY AND BIOMECHANICS OF HIP JOINT.pdf
ANATOMY AND BIOMECHANICS OF HIP JOINT.pdf
Priyankaranawat4
 
Natural birth techniques - Mrs.Akanksha Trivedi Rama University
Natural birth techniques - Mrs.Akanksha Trivedi Rama UniversityNatural birth techniques - Mrs.Akanksha Trivedi Rama University
Natural birth techniques - Mrs.Akanksha Trivedi Rama University
Akanksha trivedi rama nursing college kanpur.
 
How to Build a Module in Odoo 17 Using the Scaffold Method
How to Build a Module in Odoo 17 Using the Scaffold MethodHow to Build a Module in Odoo 17 Using the Scaffold Method
How to Build a Module in Odoo 17 Using the Scaffold Method
Celine George
 
A Independência da América Espanhola LAPBOOK.pdf
A Independência da América Espanhola LAPBOOK.pdfA Independência da América Espanhola LAPBOOK.pdf
A Independência da América Espanhola LAPBOOK.pdf
Jean Carlos Nunes Paixão
 
How to Make a Field Mandatory in Odoo 17
How to Make a Field Mandatory in Odoo 17How to Make a Field Mandatory in Odoo 17
How to Make a Field Mandatory in Odoo 17
Celine George
 
The Diamonds of 2023-2024 in the IGRA collection
The Diamonds of 2023-2024 in the IGRA collectionThe Diamonds of 2023-2024 in the IGRA collection
The Diamonds of 2023-2024 in the IGRA collection
Israel Genealogy Research Association
 
RPMS TEMPLATE FOR SCHOOL YEAR 2023-2024 FOR TEACHER 1 TO TEACHER 3
RPMS TEMPLATE FOR SCHOOL YEAR 2023-2024 FOR TEACHER 1 TO TEACHER 3RPMS TEMPLATE FOR SCHOOL YEAR 2023-2024 FOR TEACHER 1 TO TEACHER 3
RPMS TEMPLATE FOR SCHOOL YEAR 2023-2024 FOR TEACHER 1 TO TEACHER 3
IreneSebastianRueco1
 
LAND USE LAND COVER AND NDVI OF MIRZAPUR DISTRICT, UP
LAND USE LAND COVER AND NDVI OF MIRZAPUR DISTRICT, UPLAND USE LAND COVER AND NDVI OF MIRZAPUR DISTRICT, UP
LAND USE LAND COVER AND NDVI OF MIRZAPUR DISTRICT, UP
RAHUL
 

Recently uploaded (20)

PIMS Job Advertisement 2024.pdf Islamabad
PIMS Job Advertisement 2024.pdf IslamabadPIMS Job Advertisement 2024.pdf Islamabad
PIMS Job Advertisement 2024.pdf Islamabad
 
How to Fix the Import Error in the Odoo 17
How to Fix the Import Error in the Odoo 17How to Fix the Import Error in the Odoo 17
How to Fix the Import Error in the Odoo 17
 
How to Setup Warehouse & Location in Odoo 17 Inventory
How to Setup Warehouse & Location in Odoo 17 InventoryHow to Setup Warehouse & Location in Odoo 17 Inventory
How to Setup Warehouse & Location in Odoo 17 Inventory
 
PCOS corelations and management through Ayurveda.
PCOS corelations and management through Ayurveda.PCOS corelations and management through Ayurveda.
PCOS corelations and management through Ayurveda.
 
Film vocab for eal 3 students: Australia the movie
Film vocab for eal 3 students: Australia the movieFilm vocab for eal 3 students: Australia the movie
Film vocab for eal 3 students: Australia the movie
 
Pride Month Slides 2024 David Douglas School District
Pride Month Slides 2024 David Douglas School DistrictPride Month Slides 2024 David Douglas School District
Pride Month Slides 2024 David Douglas School District
 
Azure Interview Questions and Answers PDF By ScholarHat
Azure Interview Questions and Answers PDF By ScholarHatAzure Interview Questions and Answers PDF By ScholarHat
Azure Interview Questions and Answers PDF By ScholarHat
 
ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...
ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...
ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...
 
Advanced Java[Extra Concepts, Not Difficult].docx
Advanced Java[Extra Concepts, Not Difficult].docxAdvanced Java[Extra Concepts, Not Difficult].docx
Advanced Java[Extra Concepts, Not Difficult].docx
 
The basics of sentences session 6pptx.pptx
The basics of sentences session 6pptx.pptxThe basics of sentences session 6pptx.pptx
The basics of sentences session 6pptx.pptx
 
বাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdf
বাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdfবাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdf
বাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdf
 
BBR 2024 Summer Sessions Interview Training
BBR  2024 Summer Sessions Interview TrainingBBR  2024 Summer Sessions Interview Training
BBR 2024 Summer Sessions Interview Training
 
ANATOMY AND BIOMECHANICS OF HIP JOINT.pdf
ANATOMY AND BIOMECHANICS OF HIP JOINT.pdfANATOMY AND BIOMECHANICS OF HIP JOINT.pdf
ANATOMY AND BIOMECHANICS OF HIP JOINT.pdf
 
Natural birth techniques - Mrs.Akanksha Trivedi Rama University
Natural birth techniques - Mrs.Akanksha Trivedi Rama UniversityNatural birth techniques - Mrs.Akanksha Trivedi Rama University
Natural birth techniques - Mrs.Akanksha Trivedi Rama University
 
How to Build a Module in Odoo 17 Using the Scaffold Method
How to Build a Module in Odoo 17 Using the Scaffold MethodHow to Build a Module in Odoo 17 Using the Scaffold Method
How to Build a Module in Odoo 17 Using the Scaffold Method
 
A Independência da América Espanhola LAPBOOK.pdf
A Independência da América Espanhola LAPBOOK.pdfA Independência da América Espanhola LAPBOOK.pdf
A Independência da América Espanhola LAPBOOK.pdf
 
How to Make a Field Mandatory in Odoo 17
How to Make a Field Mandatory in Odoo 17How to Make a Field Mandatory in Odoo 17
How to Make a Field Mandatory in Odoo 17
 
The Diamonds of 2023-2024 in the IGRA collection
The Diamonds of 2023-2024 in the IGRA collectionThe Diamonds of 2023-2024 in the IGRA collection
The Diamonds of 2023-2024 in the IGRA collection
 
RPMS TEMPLATE FOR SCHOOL YEAR 2023-2024 FOR TEACHER 1 TO TEACHER 3
RPMS TEMPLATE FOR SCHOOL YEAR 2023-2024 FOR TEACHER 1 TO TEACHER 3RPMS TEMPLATE FOR SCHOOL YEAR 2023-2024 FOR TEACHER 1 TO TEACHER 3
RPMS TEMPLATE FOR SCHOOL YEAR 2023-2024 FOR TEACHER 1 TO TEACHER 3
 
LAND USE LAND COVER AND NDVI OF MIRZAPUR DISTRICT, UP
LAND USE LAND COVER AND NDVI OF MIRZAPUR DISTRICT, UPLAND USE LAND COVER AND NDVI OF MIRZAPUR DISTRICT, UP
LAND USE LAND COVER AND NDVI OF MIRZAPUR DISTRICT, UP
 

For this micro assignment, you must implement two Linked List functi.docx

  • 1. For this micro assignment, you must implement two Linked List functions. We will use the following example Linked List: 2 0 -1 5 7 getElementAt(index) This function should return the element (i.e. value) of the Nth item inside the linked list. For example, on the Linked List above, getElementAt(0) should return 2; getElementAt(3) should return 5. addElementAt(value, location) This function should insert a new value at the given location. Note that the location supplied must be within bounds of the LinkedList. For example, we cannot call addElementAt(4, 11) on the above Linked List because 11 is beyond the size of the Linked List. Here are some examples. If we call addElementAt(0, 1), the above Linked List would now look like: 1 2 0 -1 5 7 If we again call addElementAt(2, 123), we would get: 1 2 123 0 -1 5 7
  • 2. Grading Your submission will be graded based on the following: 1. [7] Your solution does not cause any runtime issues and your file passes all test cases 2. [3] Your code contains good style. For example, ble names @@@@@@@@@@@@@@@@@@@@@@@@ #ifndef LINKED_LIST_H #define LINKED_LIST_H #include #include #include "LinkedListNode.h" #include using namespace std;
  • 3. template class LinkedList { private: //points to the front of the linked list LinkedListNode *_front = nullptr; //keeping track of size in a variable eliminates need to continually //count LL boxes. int _size = 0; protected: //creates a new LinkedListNode for us virtual LinkedListNode *createNode(T value)
  • 4. { return new LinkedListNode < T > { value }; } public: //default constructor LinkedList() { _front = nullptr; } //copy constructor LinkedList(const LinkedList &other) { for (int i = 0; i < other.getSize(); i++) { addElement(other.getElementAt(i));
  • 5. } } //move constructor LinkedList(LinkedList &&other) { //take other's data _front = other._front; _size = other._size; //reset other's pointers other._front = nullptr; } //initializer list constructor LinkedList(initializer_list values) { for (auto item : values)
  • 6. { addElement(item); } } //Always remember to clean up pointers in destructor! virtual ~LinkedList() { LinkedListNode *current = _front; while (current != nullptr) { LinkedListNode *temp = current->getNext(); delete current; current = temp; } } //will return true if the LL is empty.
  • 7. virtual bool isEmpty() const { return _size == 0; } //returns the size of the LL. virtual int getSize() const { return _size; } //adds the supplied item to the end of our LL virtual void addElement(T value) { addElementAt(value, getSize()); } //Returns the value of the LinkedListNode at the given index
  • 8. virtual T& getElementAt(int index) { //MA #1 TODO: ACTUALLY IMPLEMENT! **************** add here int value = -1; return value; } //adds the specified item at the specified index and shifts everything else //to the "right" by one. virtual void addElementAt(T value, int location) { LinkedListNode *new_value = createNode(value); //MA #1 TODO: IMPLEMENT! ************** and here // Add variable new_value to proper location inside // our linked list.
  • 9. } }; #endif // !LINKED_LIST_H @@@@@@@@@@@@@@@@@@@@@@@ #ifndef LINKED_LIST_NODE_H #define LINKED_LIST_NODE_H //A linked list node represents a single "box" inside a lined list. In this //scheme, the LinkedList is simply a collection of LinkedListNode boxes. template class LinkedListNode { protected:
  • 10. //value that our box contains T _value; //pointer to next node in the LL sequence LinkedListNode *_next; public: //constructor must accept a default value LinkedListNode(const T &value) : _value(value) { _next = nullptr; } LinkedListNode() { _next = nullptr; }
  • 11. //copy constructor prevents premature deletion of next pointer LinkedListNode(const LinkedListNode &other) { _value = other.getValue(); _next = other.getNext(); } virtual ~LinkedListNode() { } //copy operator allows us to reassign previously created list nodes LinkedListNode &operator=(const LinkedListNode &other) { if (this != &other)
  • 12. { LinkedListNode temp(other); swap(*this, temp); } return *this; } //returns a pointer to the next list node in the sequence LinkedListNode *getNext() { return _next; } //sets the pointer to the next node in the sequence void setNext(LinkedListNode *next) { _next = next; }
  • 13. //returns the value of the list node T &getValue() { return _value; } //constant version of the getter const T& getValue() const { return _value; } //sets the value of the current list node void setValue(const T &value) { _value = value; }
  • 14. }; #endif @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ @ #include #include #include "LinkedList.h" using namespace std; void linkedListTest() { cout << "***Linked List Test***" << endl; LinkedList test_list{}; test_list.addElementAt(0, 1); test_list.addElementAt(1, 2); test_list.addElementAt(0, 3);
  • 15. test_list.addElementAt(2, 4); cout << "Number of elements in LL: " << test_list.getSize() << " (expected: 4)" << endl; cout << "Value at 0: " << test_list.getElementAt(0) << " (expected: 3)" << endl; cout << "Value at 1: " << test_list.getElementAt(1) << " (expected: 1)" << endl; cout << "Value at 2: " << test_list.getElementAt(2) << " (expected: 4)" << endl; cout << "Value at 3: " << test_list.getElementAt(3) << " (expected: 2)" << endl; } int main() { linkedListTest(); }