Explanation of Solution
Appending a node:
It is the process of adding a new node at the end of a linked list.
Inserting a node:
It is the process of adding a new node at a specific location in a list.
Member function for appending a node:
The following member function is used to append the received value into a list at end:
//Definition of appendNode() function
void IntList::appendNode(int num)
{
//Declare a structure pointer variables
ListNode *newNode, *dataPtr = nullptr;
//Assign a new node
newNode = new ListNode;
//Store the argument value into "newNode"
newNode->value = num;
//Assign the next pointer to be "NULL"
newNode->next = nullptr;
//Condition to check whether the list is empty or not
if (!head)
//If true, make newNode as the first node
head = newNode;
//else part
else
{
//Store head value into dataPtr
dataPtr = head;
//Loop to find the last node in the list
while (dataPtr->next)
//Assign last node to the structure variable
dataPtr = dataPtr->next;
//Insert newNode as the last node
dataPtr->next = newNode;
}
}
Explanation:
Consider the function named “appendNode()” to insert the received value “num” at end of the list.
- Make a new node and assign a received value “num” into the node.
- Using “if…else” condition check whether the list is empty or not.
- If the “head” node is empty, assign a new node into “head” pointer.
- Otherwise, make a loop to find a last node in the list and insert the value at end of the list.
Member function for inserting a node:
The following member function is used to insert the received value into a list at specific location:
//Definition of insertNode() function
void IntList::insertNode(int num)
{
/*Declare a structure pointer variables*/
ListNode *newNode, *dataPtr, *prev = nullptr;
//Assign a new node
newNode = new ListNode;
//Store the argument value into "newNode"
newNode->value ...
Want to see the full answer?
Check out a sample textbook solutionChapter 17 Solutions
Starting Out with C++: Early Objects
- In PYTHON Print values from the Goal column only Print values only for columns: Team, Yellow Cards and Red Cards Find and print rows for teams that scored more than 6 goals Select the teams whose name start with a G Print values only for columns Team and Shooting Accuracy , and only for rows in which the team is either of the following: England, Italy and Spain Find and print rows for teams that scored more than 6 goals and at least 4000 passesarrow_forwardIn PYTHON Print values from the Goal column only Print values only for columns: Team, Yellow Cards and Red Cards Find and print rows for teams that scored more than 6 goals Select the teams whose name start with a G Print values only for columns Team and Shooting Accuracy , and only for rows in which the team is either of the following: England, Italy and Spain Find and print rows for teams that scored more than 6 goals and at least 4000 passes Team Goals Shots on target Shots off target Shooting Accuracy Goals-to-shots (perc) Total shots (inc. Blocked) Hit Woodwork Penalty goals Penalties not scored Headed goals Passes Passes completed Passing Accuracy Touches Crosses Dribbles Corners Taken Tackles Clearances Interceptions Clearances off line Clean Sheets Blocks Goals conceded Saves made Saves-to-shots ratio Fouls Won Fouls Conceded Offsides Yellow Cards Red Cards Subs on Subs off Players Used Croatia 4 13 12 0.5 0.16 32 0 0 0 2 1076 828 0.769 1706 60…arrow_forward.Rprofile - the first chunk of code executedarrow_forward
- python The intent of this program is to manage a set of contacts. Each contact will have data associated with it: Id – number/integer First Name – string Last Name – string Age – number/integer Phone Number – string Email – string Anything else you’d like to add to make yours unique (can result in extra credit) Gender – character or string (m/f/o) Twitter ID, Facebook Id, etc You must allow the customer to do the following actions on the contact list: List all contacts Add contact Delete contact Edit contact Exit program You should leverage a database (PostgreSQL) to save everything to the DB and read from it. You should use classes for this assignment. This means you should have two classes: Contact – all the attributes/properties described above with appropriate constructor. Methods: Add (constructor - __init__(p_id, p_fname, p_lname, p_age, p_phone, p_email, p_gender) Edit Contact List (contact_list) – built on Python list (or creating one within the constructor), you…arrow_forward#arrow_forwardComputer Science:Which data type should be used to store the street name?arrow_forward
- python multiple choice Code Example 4-1 def get_username(first, last): s = first + "." + last return s.lower() def main(): first_name = input("Enter your first name: ") last_name = input("Enter your last name: ") username = get_username(first_name, last_name) print("Your username is: " + username) main() 5. Refer to Code Example 4-1: What is the scope of the variable named s ?a. globalb. localc. global in main() but local in get_username()d. local in main() but global in get_username()arrow_forwardjava programmingarrow_forwardDifferentiate between “Call by value” and “Call by Reference”.arrow_forward
- Assignment #1 Instructions: Assigning Seats - planeseats Through this programming assignment, the students will learn to do the following: 1. Know how to use a Makefile. 2. Perform basic C commands. 3. Use arrays, integers and strings. This assignment asks the user to write a program to assign seats in an airplane. There will be 12 seats on the plane, 4 in first class and 8 in economy. • The program should display the following menu for the user: Please type 1 for "first class" Please type 2 for "economy" Please type 0 to quit • If the user types 1 then the user should be assigned a seat in first class. If the user types 2 then the user should be assigned a seat in economy. • If the user types O for a sentinel value the program should ext with a O return code. • The program should then print a line indicating the seat the person was assigned. This would be like a boarding pass. • The program should not assign a seat that has already been assigned. If all seats in the desired section…arrow_forwardC#arrow_forwardWork Sheets Q2: What do you means by identifiers? What is the maximum length of dentifiers?arrow_forward
- Programming Logic & Design ComprehensiveComputer ScienceISBN:9781337669405Author:FARRELLPublisher:Cengage