SlideShare una empresa de Scribd logo
1 de 15
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();
}

Más contenido relacionado

Similar a 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.pdfezycolours78
 
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.pdfmail931892
 
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.pdfinfo430661
 
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.pdfannaelctronics
 
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.pdfsales98
 
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.pdffcaindore
 
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.pdffeelinggift
 
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.pdfarchgeetsenterprises
 
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-.pdfvishalateen
 
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..pdffacevenky
 
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.pdfbabitasingh698417
 
public class MyLinkedListltE extends ComparableltEgtg.pdf
public class MyLinkedListltE extends ComparableltEgtg.pdfpublic class MyLinkedListltE extends ComparableltEgtg.pdf
public class MyLinkedListltE extends ComparableltEgtg.pdfaccostinternational
 
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 .pdfrohit219406
 
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.pdffreddysarabia1
 
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.pdfstopgolook
 
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.pdfinfo706022
 
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.pdfConint29
 
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.pdfinfo114
 
Please help me to make a programming project I have to sue them today- (1).pdf
Please help me to make a programming project I have to sue them today- (1).pdfPlease help me to make a programming project I have to sue them today- (1).pdf
Please help me to make a programming project I have to sue them today- (1).pdfseoagam1
 

Similar a 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
 
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
 
Please help me to make a programming project I have to sue them today- (1).pdf
Please help me to make a programming project I have to sue them today- (1).pdfPlease help me to make a programming project I have to sue them today- (1).pdf
Please help me to make a programming project I have to sue them today- (1).pdf
 

Más de 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 .docxmckellarhastings
 
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.docxmckellarhastings
 
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 .docxmckellarhastings
 
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.docxmckellarhastings
 
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.docxmckellarhastings
 
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.docxmckellarhastings
 
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.docxmckellarhastings
 
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 .docxmckellarhastings
 
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.docxmckellarhastings
 
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.docxmckellarhastings
 
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.docxmckellarhastings
 
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,.docxmckellarhastings
 
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.docxmckellarhastings
 
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.docxmckellarhastings
 
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 .docxmckellarhastings
 
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.docxmckellarhastings
 
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.docxmckellarhastings
 
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.docxmckellarhastings
 
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.docxmckellarhastings
 
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, .docxmckellarhastings
 

Más de 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
 

Último

Disha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfDisha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfchloefrazer622
 
9548086042 for call girls in Indira Nagar with room service
9548086042  for call girls in Indira Nagar  with room service9548086042  for call girls in Indira Nagar  with room service
9548086042 for call girls in Indira Nagar with room servicediscovermytutordmt
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAssociation for Project Management
 
Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfchloefrazer622
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionSafetyChain Software
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingTechSoup
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104misteraugie
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfsanyamsingh5019
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactdawncurless
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxiammrhaywood
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactPECB
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdfQucHHunhnh
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)eniolaolutunde
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeThiyagu K
 
social pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajansocial pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajanpragatimahajan3
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfciinovamais
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityGeoBlogs
 
JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...
JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...
JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...anjaliyadav012327
 
Student login on Anyboli platform.helpin
Student login on Anyboli platform.helpinStudent login on Anyboli platform.helpin
Student login on Anyboli platform.helpinRaunakKeshri1
 
mini mental status format.docx
mini    mental       status     format.docxmini    mental       status     format.docx
mini mental status format.docxPoojaSen20
 

Último (20)

Disha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfDisha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdf
 
9548086042 for call girls in Indira Nagar with room service
9548086042  for call girls in Indira Nagar  with room service9548086042  for call girls in Indira Nagar  with room service
9548086042 for call girls in Indira Nagar with room service
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across Sectors
 
Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdf
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory Inspection
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy Consulting
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdf
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impact
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global Impact
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and Mode
 
social pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajansocial pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajan
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activity
 
JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...
JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...
JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...
 
Student login on Anyboli platform.helpin
Student login on Anyboli platform.helpinStudent login on Anyboli platform.helpin
Student login on Anyboli platform.helpin
 
mini mental status format.docx
mini    mental       status     format.docxmini    mental       status     format.docx
mini mental status format.docx
 

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(); }