In computer science, a linked list is a linear collection of data elements, in which linear order is not given by their physical placement in memory. Instead, each element points to the next
This assignment and the next (#5) involve design and development of a.pdfEricvtJFraserr
This assignment and the next (#5) involve design and development of a sequential
non contiguous and dynamic datastructure called LinkedList. A linked list object is
a container consisting of connected ListNode objects. As before, we are not going
to use pre-fabricated classes from the c++ library, but construct the LinkedList
ADT from scratch.
The first step is construction and testing of the ListNode class. A ListNode object
contains a data field and a pointer to the next ListNode object (note the recursive
definition).
#This assignment requires you to
1. Read the Assignment 4 Notes
2. Watch the Assignment 4 Support video
3. Implement the following methods of the ListNode class
-custom constructor
-setters for next pointer and data
4. Implement the insert and remove method in the main program
5. Scan the given template to find the above //TODO and implement the code
needed
//TODO in ListNodecpp.h file
public: ListNode(T idata, ListNode<T> * newNext);
public: void setNext(ListNode<T> * newNext);
public: void setData(T newData);
// TODO in main program
void remove(ListNode<int> * &front,int value)
void insert(ListNode<int> * &front,int value)
# The driver is given ListNodeMain.cpp is given to you that does the following
tests
1. Declares a pointer called front to point to a ListNode of datatype integer
2. Constructs four ListNodes with data 1,2,4 and adds them to form a linked
list.
3. Inserts ListNode with data 3 to the list
4. Removes node 1 and adds it back to test removing and adding the first
element
5. Removes node 3 to test removing a middle node
6. Removes node 4 to test removing the last node
7. Attempt to remove a non existent node
8. Remove all existing nodes to empty the list
9. Insert node 4 and then node 1 to test if insertions preserve order
10.Print the list
Main.cpp
#include <iostream>
#include "ListNodecpp.h"
// REMEMBER each ListNode has two parts : a data field
// and an address field. The address is either null or points to the next node
//in the chain
//Requires: integer value for searching, address of front
//Effects: traverses the list node chain starting from front until the end comparing search value
with listnode getData. Returns the original search value if found, if not adds +1 to indicate not
found
//Modifies: Nothing
int search(ListNode<int> * front, int value);
//Requires: integer value for inserting, address of front
//Effects: creates a new ListNode with value and inserts in proper position (increasing order)in
the chain. If chain is empty, adds to the beginning
//Modifies: front, if node is added at the beginning.
//Also changes the next pointer of the previous node to point to the
//newly inserted list node. the next pointer of the newly inserted pointer
//points to what was the next of the previous node.
//This way both previous and current links are adjusted
//******** NOTE the use of & in passing pointer to front as parameter -
// Why do you think this is needed ?**********
void insert(ListNode<int> * &fr.
In computer science, a linked list is a linear collection of data elements, in which linear order is not given by their physical placement in memory. Instead, each element points to the next
This assignment and the next (#5) involve design and development of a.pdfEricvtJFraserr
This assignment and the next (#5) involve design and development of a sequential
non contiguous and dynamic datastructure called LinkedList. A linked list object is
a container consisting of connected ListNode objects. As before, we are not going
to use pre-fabricated classes from the c++ library, but construct the LinkedList
ADT from scratch.
The first step is construction and testing of the ListNode class. A ListNode object
contains a data field and a pointer to the next ListNode object (note the recursive
definition).
#This assignment requires you to
1. Read the Assignment 4 Notes
2. Watch the Assignment 4 Support video
3. Implement the following methods of the ListNode class
-custom constructor
-setters for next pointer and data
4. Implement the insert and remove method in the main program
5. Scan the given template to find the above //TODO and implement the code
needed
//TODO in ListNodecpp.h file
public: ListNode(T idata, ListNode<T> * newNext);
public: void setNext(ListNode<T> * newNext);
public: void setData(T newData);
// TODO in main program
void remove(ListNode<int> * &front,int value)
void insert(ListNode<int> * &front,int value)
# The driver is given ListNodeMain.cpp is given to you that does the following
tests
1. Declares a pointer called front to point to a ListNode of datatype integer
2. Constructs four ListNodes with data 1,2,4 and adds them to form a linked
list.
3. Inserts ListNode with data 3 to the list
4. Removes node 1 and adds it back to test removing and adding the first
element
5. Removes node 3 to test removing a middle node
6. Removes node 4 to test removing the last node
7. Attempt to remove a non existent node
8. Remove all existing nodes to empty the list
9. Insert node 4 and then node 1 to test if insertions preserve order
10.Print the list
Main.cpp
#include <iostream>
#include "ListNodecpp.h"
// REMEMBER each ListNode has two parts : a data field
// and an address field. The address is either null or points to the next node
//in the chain
//Requires: integer value for searching, address of front
//Effects: traverses the list node chain starting from front until the end comparing search value
with listnode getData. Returns the original search value if found, if not adds +1 to indicate not
found
//Modifies: Nothing
int search(ListNode<int> * front, int value);
//Requires: integer value for inserting, address of front
//Effects: creates a new ListNode with value and inserts in proper position (increasing order)in
the chain. If chain is empty, adds to the beginning
//Modifies: front, if node is added at the beginning.
//Also changes the next pointer of the previous node to point to the
//newly inserted list node. the next pointer of the newly inserted pointer
//points to what was the next of the previous node.
//This way both previous and current links are adjusted
//******** NOTE the use of & in passing pointer to front as parameter -
// Why do you think this is needed ?**********
void insert(ListNode<int> * &fr.
I am Gabriel C. I am a C Exam Expert at programmingexamhelp.com. I hold a PhD. in Business analyst of Information Technology, Montreal College of Information Technology, Canada. I have been helping students with their exams for the past 8 years. You can hire me to take your exam in C.
Visit programmingexamhelp.com or email support@programmingexamhelp.com. You can also call on +1 678 648 4277 for any assistance with the C Exam.
C++ Please write the whole code that is needed for this assignment- wr.docxBrianGHiNewmanv
Brianca plans to save $5,000, $1,000, and $42,000 a year over the next three years, respectively. How much would you need to deposit in one lump sum today to have the same amount as Brianca three years from now if you both earn 10.9 percent, compounded annually? $36,115 $35,192 $43,282 $41,635 $35,372
.
I am Andrew O. I am a C Homework Expert at programminghomeworkhelp.com. I hold a master’s in Programming from, the University of Southampton, UK. I have been helping students with their homework for the past 10 years. I solve homework related to C.
Visit programminghomeworkhelp.com or email support@programminghomeworkhelp.com.
You can also call on +1 678 648 4277 for any assistance with C Homework.
Need done for Date Structures please! 4-18 LAB- Sorted number list imp.pdfinfo114
Need done for Date Structures please!
4.18 LAB: Sorted number list implementation with linked lists
Step 1: Inspect the Node.h file
Inspect the class declaration for a doubly-linked list node in Node.h. Access Node.h by clicking
on the orange arrow next to main.cpp at the top of the coding window. The Node class has three
member variables:
a double data value,
a pointer to the next node, and
a pointer to the previous node.
Each member variable is protected. So code outside of the class must use the provided getter and
setter member functions to get or set a member variable.
Node.h is read only, since no changes are required.
Step 2: Implement the Insert() member function
A class for a sorted, doubly-linked list is declared in SortedNumberList.h. Implement the
SortedNumberList class's Insert() member function. The function must create a new node with
the parameter value, then insert the node into the proper sorted position in the linked list. Ex:
Suppose a SortedNumberList's current list is 23 47.25 86, then Insert(33.5) is called. A new node
with data value 33.5 is created and inserted between 23 and 47.25, thus preserving the list's
sorted order and yielding: 23 35.5 47.25 86
Step 3: Test in develop mode
Code in main() takes a space-separated list of numbers and inserts each into a SortedNumberList.
The list is displayed after each insertion. Ex: If input is
then output is:
Try various program inputs, ensuring that each outputs a sorted list.
Step 4: Implement the Remove() member function
Implement the SortedNumberList class's Remove() member function. The function takes a
parameter for the number to be removed from the list. If the number does not exist in the list, the
list is not changed and false is returned. Otherwise, the first instance of the number is removed
from the list and true is returned.
Uncomment the commented-out part in main() that reads a second input line and removes
numbers from the list. Test in develop mode to ensure that insertion and removal both work
properly, then submit code for grading. Ex: If input is
then output is:
main.cpp
#include <iostream>
#include <string>
#include <vector>
#include "Node.h"
#include "SortedNumberList.h"
using namespace std;
void PrintList(SortedNumberList& list);
vector<string> SpaceSplit(string source);
int main(int argc, char *argv[]) {
// Read the line of input numbers
string inputLine;
getline(cin, inputLine);
// Split on space character
vector<string> terms = SpaceSplit(inputLine);
// Insert each value and show the sorted list's contents after each insertion
SortedNumberList list;
for (auto term : terms) {
double number = stod(term);
cout << "List after inserting " << number << ": " << endl;
list.Insert(number);
PrintList(list);
}
/*
// Read the input line with numbers to remove
getline(cin, inputLine);
terms = SpaceSplit(inputLine);
// Remove each value
for (auto term : terms) {
double number = stod(term);
cout << "List after removing " << number << ": " << endl;
list.Remove(number.
A Computer Science portal for geeks. It contains well written, well thought and well explained computer science and programming articles, quizzes and practice/competitive programming/company interview Questions.
Inspect the class declaration for a doubly-linked list node in Node-h-.pdfvishalateen
Inspect the class declaration for a doubly-linked list node in Node.h. Access Node.h by clicking
on the orange arrow next to main.cpp at the top of the coding window. The Node class has three
member variables: a double data value, a pointer to the next node, and a pointer to the previous
node. Each member variable is protected. So code outside of the class must use the provided
getter and setter member functions to get or set a member variable. Node.h is read only, since no
changes are required. Step 2: Implement the Insert() member function A class for a sorted,
doubly-linked list is declared in SortedNumberList.h. Implement the SortedNumberList class's
Insert() member function. The function must create a new node with the parameter value, then
insert the node into the proper sorted position in the linked list. Ex: Suppose a
SortedNumberList's current list is 23 47.25 86, then Insert(33.5) is called. A new node with data
value 33.5 is created and inserted between 23 and 47.25, thus preserving the list's sorted order
and yielding: 23 35.5 47.25 86 Step 3: Test in develop mode Code in main() takes a space-
separated list of numbers and inserts each into a SortedNumberList. The list is displayed after
each insertion. Ex: If input is 77 15 -42 63.5 then output is: List after inserting 77: 77 List after
inserting 15: 15 77 List after inserting -42: -42 15 77 List after inserting 63.5: -42 15 63.5 77 Try
various program inputs, ensuring that each outputs a sorted list. Step 4: Implement the Remove()
member function Implement the SortedNumberList class's Remove() member function. The
function takes a parameter for the number to be removed from the list. If the number does not
exist in the list, the list is not changed and false is returned. Otherwise, the first instance of the
number is removed from the list and true is returned. Uncomment the commented-out part in
main() that reads a second input line and removes numbers from the list. Test in develop mode to
ensure that insertion and removal both work properly, then submit code for grading. Ex: If input
is 84 72 19 61 19 84 then output is: List after inserting 84: 84 List after inserting 72: 72 84 List
after inserting 19: 19 72 84 List after inserting 61: 19 61 72 84 List after removing 19: 61 72 84
List after removing 84: 61 72
main.cpp
#include
#include
#include
#include "Node.h"
#include "SortedNumberList.h"
using namespace std; void PrintList(SortedNumberList& list); vector SpaceSplit(string source);
int main(int argc, char *argv[]) { // Read the line of input numbers string inputLine; getline(cin,
inputLine); // Split on space character vector terms = SpaceSplit(inputLine); // Insert each value
and show the sorted list's contents after each insertion SortedNumberList list; for (auto term :
terms) { double number = stod(term); cout << "List after inserting " << number << ": " << endl;
list.Insert(number); PrintList(list); } /* // Read the input line with numbers to remove getline(cin,
inputLi.
Chatty Kathy - UNC Bootcamp Final Project Presentation - Final Version - 5.23...John Andrews
SlideShare Description for "Chatty Kathy - UNC Bootcamp Final Project Presentation"
Title: Chatty Kathy: Enhancing Physical Activity Among Older Adults
Description:
Discover how Chatty Kathy, an innovative project developed at the UNC Bootcamp, aims to tackle the challenge of low physical activity among older adults. Our AI-driven solution uses peer interaction to boost and sustain exercise levels, significantly improving health outcomes. This presentation covers our problem statement, the rationale behind Chatty Kathy, synthetic data and persona creation, model performance metrics, a visual demonstration of the project, and potential future developments. Join us for an insightful Q&A session to explore the potential of this groundbreaking project.
Project Team: Jay Requarth, Jana Avery, John Andrews, Dr. Dick Davis II, Nee Buntoum, Nam Yeongjin & Mat Nicholas
I am Gabriel C. I am a C Exam Expert at programmingexamhelp.com. I hold a PhD. in Business analyst of Information Technology, Montreal College of Information Technology, Canada. I have been helping students with their exams for the past 8 years. You can hire me to take your exam in C.
Visit programmingexamhelp.com or email support@programmingexamhelp.com. You can also call on +1 678 648 4277 for any assistance with the C Exam.
C++ Please write the whole code that is needed for this assignment- wr.docxBrianGHiNewmanv
Brianca plans to save $5,000, $1,000, and $42,000 a year over the next three years, respectively. How much would you need to deposit in one lump sum today to have the same amount as Brianca three years from now if you both earn 10.9 percent, compounded annually? $36,115 $35,192 $43,282 $41,635 $35,372
.
I am Andrew O. I am a C Homework Expert at programminghomeworkhelp.com. I hold a master’s in Programming from, the University of Southampton, UK. I have been helping students with their homework for the past 10 years. I solve homework related to C.
Visit programminghomeworkhelp.com or email support@programminghomeworkhelp.com.
You can also call on +1 678 648 4277 for any assistance with C Homework.
Need done for Date Structures please! 4-18 LAB- Sorted number list imp.pdfinfo114
Need done for Date Structures please!
4.18 LAB: Sorted number list implementation with linked lists
Step 1: Inspect the Node.h file
Inspect the class declaration for a doubly-linked list node in Node.h. Access Node.h by clicking
on the orange arrow next to main.cpp at the top of the coding window. The Node class has three
member variables:
a double data value,
a pointer to the next node, and
a pointer to the previous node.
Each member variable is protected. So code outside of the class must use the provided getter and
setter member functions to get or set a member variable.
Node.h is read only, since no changes are required.
Step 2: Implement the Insert() member function
A class for a sorted, doubly-linked list is declared in SortedNumberList.h. Implement the
SortedNumberList class's Insert() member function. The function must create a new node with
the parameter value, then insert the node into the proper sorted position in the linked list. Ex:
Suppose a SortedNumberList's current list is 23 47.25 86, then Insert(33.5) is called. A new node
with data value 33.5 is created and inserted between 23 and 47.25, thus preserving the list's
sorted order and yielding: 23 35.5 47.25 86
Step 3: Test in develop mode
Code in main() takes a space-separated list of numbers and inserts each into a SortedNumberList.
The list is displayed after each insertion. Ex: If input is
then output is:
Try various program inputs, ensuring that each outputs a sorted list.
Step 4: Implement the Remove() member function
Implement the SortedNumberList class's Remove() member function. The function takes a
parameter for the number to be removed from the list. If the number does not exist in the list, the
list is not changed and false is returned. Otherwise, the first instance of the number is removed
from the list and true is returned.
Uncomment the commented-out part in main() that reads a second input line and removes
numbers from the list. Test in develop mode to ensure that insertion and removal both work
properly, then submit code for grading. Ex: If input is
then output is:
main.cpp
#include <iostream>
#include <string>
#include <vector>
#include "Node.h"
#include "SortedNumberList.h"
using namespace std;
void PrintList(SortedNumberList& list);
vector<string> SpaceSplit(string source);
int main(int argc, char *argv[]) {
// Read the line of input numbers
string inputLine;
getline(cin, inputLine);
// Split on space character
vector<string> terms = SpaceSplit(inputLine);
// Insert each value and show the sorted list's contents after each insertion
SortedNumberList list;
for (auto term : terms) {
double number = stod(term);
cout << "List after inserting " << number << ": " << endl;
list.Insert(number);
PrintList(list);
}
/*
// Read the input line with numbers to remove
getline(cin, inputLine);
terms = SpaceSplit(inputLine);
// Remove each value
for (auto term : terms) {
double number = stod(term);
cout << "List after removing " << number << ": " << endl;
list.Remove(number.
A Computer Science portal for geeks. It contains well written, well thought and well explained computer science and programming articles, quizzes and practice/competitive programming/company interview Questions.
Inspect the class declaration for a doubly-linked list node in Node-h-.pdfvishalateen
Inspect the class declaration for a doubly-linked list node in Node.h. Access Node.h by clicking
on the orange arrow next to main.cpp at the top of the coding window. The Node class has three
member variables: a double data value, a pointer to the next node, and a pointer to the previous
node. Each member variable is protected. So code outside of the class must use the provided
getter and setter member functions to get or set a member variable. Node.h is read only, since no
changes are required. Step 2: Implement the Insert() member function A class for a sorted,
doubly-linked list is declared in SortedNumberList.h. Implement the SortedNumberList class's
Insert() member function. The function must create a new node with the parameter value, then
insert the node into the proper sorted position in the linked list. Ex: Suppose a
SortedNumberList's current list is 23 47.25 86, then Insert(33.5) is called. A new node with data
value 33.5 is created and inserted between 23 and 47.25, thus preserving the list's sorted order
and yielding: 23 35.5 47.25 86 Step 3: Test in develop mode Code in main() takes a space-
separated list of numbers and inserts each into a SortedNumberList. The list is displayed after
each insertion. Ex: If input is 77 15 -42 63.5 then output is: List after inserting 77: 77 List after
inserting 15: 15 77 List after inserting -42: -42 15 77 List after inserting 63.5: -42 15 63.5 77 Try
various program inputs, ensuring that each outputs a sorted list. Step 4: Implement the Remove()
member function Implement the SortedNumberList class's Remove() member function. The
function takes a parameter for the number to be removed from the list. If the number does not
exist in the list, the list is not changed and false is returned. Otherwise, the first instance of the
number is removed from the list and true is returned. Uncomment the commented-out part in
main() that reads a second input line and removes numbers from the list. Test in develop mode to
ensure that insertion and removal both work properly, then submit code for grading. Ex: If input
is 84 72 19 61 19 84 then output is: List after inserting 84: 84 List after inserting 72: 72 84 List
after inserting 19: 19 72 84 List after inserting 61: 19 61 72 84 List after removing 19: 61 72 84
List after removing 84: 61 72
main.cpp
#include
#include
#include
#include "Node.h"
#include "SortedNumberList.h"
using namespace std; void PrintList(SortedNumberList& list); vector SpaceSplit(string source);
int main(int argc, char *argv[]) { // Read the line of input numbers string inputLine; getline(cin,
inputLine); // Split on space character vector terms = SpaceSplit(inputLine); // Insert each value
and show the sorted list's contents after each insertion SortedNumberList list; for (auto term :
terms) { double number = stod(term); cout << "List after inserting " << number << ": " << endl;
list.Insert(number); PrintList(list); } /* // Read the input line with numbers to remove getline(cin,
inputLi.
Chatty Kathy - UNC Bootcamp Final Project Presentation - Final Version - 5.23...John Andrews
SlideShare Description for "Chatty Kathy - UNC Bootcamp Final Project Presentation"
Title: Chatty Kathy: Enhancing Physical Activity Among Older Adults
Description:
Discover how Chatty Kathy, an innovative project developed at the UNC Bootcamp, aims to tackle the challenge of low physical activity among older adults. Our AI-driven solution uses peer interaction to boost and sustain exercise levels, significantly improving health outcomes. This presentation covers our problem statement, the rationale behind Chatty Kathy, synthetic data and persona creation, model performance metrics, a visual demonstration of the project, and potential future developments. Join us for an insightful Q&A session to explore the potential of this groundbreaking project.
Project Team: Jay Requarth, Jana Avery, John Andrews, Dr. Dick Davis II, Nee Buntoum, Nam Yeongjin & Mat Nicholas
Levelwise PageRank with Loop-Based Dead End Handling Strategy : SHORT REPORT ...Subhajit Sahu
Abstract — Levelwise PageRank is an alternative method of PageRank computation which decomposes the input graph into a directed acyclic block-graph of strongly connected components, and processes them in topological order, one level at a time. This enables calculation for ranks in a distributed fashion without per-iteration communication, unlike the standard method where all vertices are processed in each iteration. It however comes with a precondition of the absence of dead ends in the input graph. Here, the native non-distributed performance of Levelwise PageRank was compared against Monolithic PageRank on a CPU as well as a GPU. To ensure a fair comparison, Monolithic PageRank was also performed on a graph where vertices were split by components. Results indicate that Levelwise PageRank is about as fast as Monolithic PageRank on the CPU, but quite a bit slower on the GPU. Slowdown on the GPU is likely caused by a large submission of small workloads, and expected to be non-issue when the computation is performed on massive graphs.
Explore our comprehensive data analysis project presentation on predicting product ad campaign performance. Learn how data-driven insights can optimize your marketing strategies and enhance campaign effectiveness. Perfect for professionals and students looking to understand the power of data analysis in advertising. for more details visit: https://bostoninstituteofanalytics.org/data-science-and-artificial-intelligence/
Predicting Product Ad Campaign Performance: A Data Analysis Project Presentation
linkedlistwith animations.ppt
1. This presentation shows how to
implement the most common
operations on linked lists.
Linked Lists in Action
2. For this presentation, nodes in a
linked list are objects, as shown here.
data_field
link_field
10
data_field
link_field
15
data_field
link_field
7
null
class node
{
public:
typedef double value_type;
...
private
value_type data_field;
node *link_field;
};
Declarations for Linked Lists
3. The data_field of each node is a type called
value_type, defined by a typedef.
data_field
link_field
10
data_field
link_field
15
data_field
link_field
7
null
class node
{
public:
typedef int value_type;
...
private
value_type data_field;
node *link_field;
};
Declarations for Linked Lists
4. Each node also contains a link_field
which is a pointer to another node.
data_field
link_field
10
data_field
link_field
15
data_field
link_field
7
null
class node
{
public:
typedef int value_type;
...
private
value_type data_field;
node *link_field;
};
Declarations for Linked Lists
5. Declarations for Linked Lists
A program can keep track of the front
node by using a pointer variable such
as head_ptr in this example.
Notice that head_ptr is not a node -- it
is a pointer to a node.
head_ptr
data_field
link_field
10
data_field
link_field
15
data_field
link_field
7
null
6. Declarations for Linked Lists
A program can keep track of the front
node by using a pointer variable such
as head_ptr.
Notice that head_ptr is not a node -- it
is a pointer to a node.
We represent the empty list by storing
null in the head pointer.
head_ptr
null
7. void list_head_insert(node*& head_ptr, const node::value_type& entry);
Inserting a Node at the Front
We want to add a new entry, 13,
to the front of the linked list
shown here.
10
15
7
null
head_ptr
entry
13
8. Inserting a Node at the Front
Create a new node, pointed to
by a local variable insert_ptr.
10
15
7
null
head_ptr
entry
13
insert_ptr
void list_head_insert(node*& head_ptr, const node::value_type& entry);
9. Inserting a Node at the Front
insert_ptr = new node;
10
15
7
null
head_ptr
entry
13
insert_ptr
void list_head_insert(node*& head_ptr, const node::value_type& entry);
10. Inserting a Node at the Front
10
15
7
null
head_ptr
entry
13
insert_ptr
13
insert_ptr = new node;
Place the data in the new node's
data_field.
void list_head_insert(node*& head_ptr, const node::value_type& entry);
11. Inserting a Node at the Front
10
15
7
null
head_ptr
entry
13
insert_ptr
13
insert_ptr = new node;
Place the data in the new node's
data_field.
Connect the new node to the
front of the list.
void list_head_insert(node*& head_ptr, const node::value_type& entry);
12. Inserting a Node at the Front
10
15
7
null
head_ptr
entry
13
insert_ptr
13
insert_ptr = new node(entry, head_ptr);
The correct new node
can be completely
created in one step by
calling an appropriate
node constructor.
void list_head_insert(node*& head_ptr, const node::value_type& entry);
13. Inserting a Node at the Front
10
15
7
null
head_ptr
entry
13
insert_ptr
13
insert_ptr = new node(entry, head_ptr);
Make the old head pointer
point to the new node.
void list_head_insert(node*& head_ptr, const node::value_type& entry);
14. Inserting a Node at the Front
10
15
7
null
head_ptr
entry
13
insert_ptr
13
insert_ptr = new node(entry, head_ptr);
head_ptr = insert_ptr;
void list_head_insert(node*& head_ptr, const node::value_type& entry);
15. Inserting a Node at the Front
insert_ptr = new node(entry, head_ptr);
head_ptr = insert_ptr;
10
15
7
null
head_ptr
13
When the function returns, the
linked list has a new node at the
front.
void list_head_insert(node*& head_ptr, const node::value_type& entry);
16. void list_head_insert(node*& head_ptr, const node::value_type& entry)
{
node *insert_ptr;
insert_ptr = new node(entry, head_ptr);
head_ptr = insert_ptr;
}
Inserting a Node at the Front
17. Inserting a Node at the Front
void list_head_insert(node*& head_ptr, const node::value_type& entry)
{
node *insert_ptr;
insert_ptr = new node(entry, head_ptr);
head_ptr = insert_ptr;
}
Does the function work
correctly for the empty
list ?
18. head_ptr
entry
13 null
Inserting a Node at the Front
Does the function work
correctly for the empty
list ?
void list_head_insert(node*& head_ptr, const node::value_type& entry)
{
node *insert_ptr;
insert_ptr = new node(entry, head_ptr);
head_ptr = insert_ptr;
}
19. Inserting a Node at the Front
head_ptr
entry
13 null
insert_ptr
13
void list_head_insert(node*& head_ptr, const node::value_type& entry)
{
node *insert_ptr;
insert_ptr = new node(entry, head_ptr);
head_ptr = insert_ptr;
}
null
20. Inserting a Node at the Front
head_ptr
entry
13
insert_ptr
13
null
void list_head_insert(node*& head_ptr, const node::value_type& entry)
{
node *insert_ptr;
insert_ptr = new node(entry, head_ptr);
head_ptr = insert_ptr;
}
21. Inserting a Node at the Front
head_ptr
13
null
void list_head_insert(node*& head_ptr, const node::value_type& entry)
{
node *insert_ptr;
insert_ptr = new node(entry, head_ptr);
head_ptr = insert_ptr;
}
When the function
returns, the linked list
has one node.
22. Caution!
Always make sure that
your linked list
functions work
correctly with an
empty list.
EMPTY LIST
23. Pseudocode for Inserting Nodes
Nodes are often inserted at places other than the
front of a linked list.
There is a general pseudocode that you can follow
for any insertion function. . .
24. Pseudocode for Inserting Nodes
Determine whether the new node will be the first node in
the linked list. If so, then there is only one step:
list_head_insert(head_ptr, entry);
25. Pseudocode for Inserting Nodes
Determine whether the new node will be the first node in
the linked list. If so, then there is only one step:
list_head_insert(head_ptr, entry);
26. Pseudocode for Inserting Nodes
Determine whether the new node will be the first node in
the linked list. If so, then there is only one step:
list_head_insert(head_ptr, entry);
A pointer
to the
head of
the list
27. Pseudocode for Inserting Nodes
Determine whether the new node will be the first node in
the linked list. If so, then there is only one step:
list_head_insert(head_ptr, entry);
28. Pseudocode for Inserting Nodes
Otherwise (if the new node will not be first):
Start by setting a pointer named previous_ptr to point to the
node which is just before the new node's position.
29. Pseudocode for Inserting Nodes
15
10
7
null
head_ptr
Otherwise (if the new node will not be first):
Start by setting a pointer named previous_ptr to point to the
node which is just before the new node's position.
In this example, the
new node will be
the second node
previous_ptr
30. Pseudocode for Inserting Nodes
15
10
7
null
head_ptr
Otherwise (if the new node will not be first):
Start by setting a pointer named previous_ptr to point to the
node which is just before the new node's position
What is the name of
this orange pointer ?
Look at the pointer
which is in the node
*previous_ptr
previous_ptr
31. Pseudocode for Inserting Nodes
15
10
7
null
head_ptr
Otherwise (if the new node will not be first):
Start by setting a pointer named previous_ptr to point to the
node which is just before the new node's position
This pointer is called
previous_ptr->link_field
(although this name may
be private to the node)
What is the name of
this orange pointer ?
previous_ptr
32. Pseudocode for Inserting Nodes
15
10
7
null
head_ptr
Otherwise (if the new node will not be first):
Start by setting a pointer named previous_ptr to point to the
node which is just before the new node's position
previous_ptr->link_field
points to the head
of a small linked
list, with 10 and 7
previous_ptr
33. Pseudocode for Inserting Nodes
15
10
7
null
head_ptr
Otherwise (if the new node will not be first):
Start by setting a pointer named previous_ptr to point to the
node which is just before the new node's position.
The new node must
be inserted at the
front of this small
linked list.
13
Write one C++ statement
which will do the insertion.
previous_ptr
34. Pseudocode for Inserting Nodes
15
10
7
null
head_ptr
Otherwise (if the new node will not be first):
Start by setting a pointer named previous_ptr to point to the
node which is just before the new node's position.
13
What might cause this
statement to fail to compile?
previous_ptr
list_head_insert(previous_ptr->link_field, entry);
35. Pseudocode for Inserting Nodes
15
10
7
null
head_ptr
Otherwise (if the new node will not be first):
Start by setting a pointer named previous_ptr to point to the
node which is just before the new node's position.
13
Use a node member function
to get the link field if
needed.
previous_ptr
list_head_insert(previous_ptr->link( ), entry);
36. Pseudocode for Inserting Nodes
Determine whether the new node will be the first node in
the linked list. If so, then there is only one step:
list_head_insert(head_ptr, entry);
Otherwise (if the new node will not be first):
Set a pointer named previous_ptr to point to the node
which is just before the new node's position.
Make the function call:
list_head_insert(previous_ptr->link( ), entry);
37. Pseudocode for Inserting Nodes
The process of adding a new node in the middle
of a list can also be incorporated as a separate
function. This function is called list_insert in the
linked list toolkit of Section 5.2.
38. Pseudocode for Removing Nodes
Nodes often need to be removed from a linked list.
As with insertion, there is a technique for removing
a node from the front of a list, and a technique for
removing a node from elsewhere.
We’ll look at the pseudocode for removing a node
from the front of a linked list.
39. Removing the Head Node
10 15 7
null
head_ptr
13
Start by setting up a temporary pointer named remove_ptr to
the head node.
remove_ptr
40. Removing the Head Node
10 15 7
null
head_ptr
13
Set up remove_ptr.
head_ptr = remove_ptr->link( );
remove_ptr
Draw the change that this
statement will make to the
linked list.
41. Removing the Head Node
10 15 7
null
head_ptr
13
Set up remove_ptr.
head_ptr = remove_ptr->link( );
remove_ptr
42. Removing the Head Node
Set up remove_ptr.
head_ptr = remove_ptr->link( );
delete remove_ptr; // Return the node's memory to heap.
10 15 7
null
head_ptr
13
remove_ptr
43. Removing the Head Node
Here’s what the linked list looks like after the removal finishes.
10 15 7
null
head_ptr
44. It is easy to insert a node at the front of a list.
The linked list toolkit also provides a function for
inserting a new node elsewhere
It is easy to remove a node at the front of a list.
The linked list toolkit also provides a function for
removing a node elsewhere--you should read
about this function and the other functions of the
toolkit.
Summary