Starting Out with C++: Early Objects (9th Edition)
9th Edition
ISBN: 9780134400242
Author: Tony Gaddis, Judy Walters, Godfrey Muganda
Publisher: PEARSON
expand_more
expand_more
format_list_bulleted
Concept explainers
Expert Solution & Answer
Chapter 17, Problem 8RQE
Program Description Answer
In a linked list, each node contains a pointer to the one before it and the one after it is referred as “doubly linked list”.
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
Computer Science
lab3.h
-------------
#include<stdio.h>
#include<stdlib.h>
#ifndef LAB3_H
#define LAB3_H
// A linked list node
struct Node
{
int data; //Data
struct Node *next; // Address to the next node
};
//initialize: create an empty head node (whose "data" is intentionally missing); This head node will not be used to store any data;
struct Node *init () {
//create head node
struct Node *head = (struct Node*)malloc(sizeof(struct Node));
}
//Create a new node to store data and insert it to the end of current linked list; the head node will still be empty and data in the array in "main.c" are not stored in head node
void insert(struct node *head, int data) {
struct Node *newNode = (struct Node*)malloc(sizeof(struct Node));
new_node->data = data;
new_node->next= head;
}
//print data for all nodes in the linked list except the head node (which is empty)
void display (struct Node *head) {
struct Node *current_node = head;
while ( current_node != NULL) {
printf("%d ",…
// FILL IN THE BLANKS (LINKED-LISTS CODE) (C++)#include<iostream>using namespace std;
struct ________ {int data ;struct node *next; };
node *head = ________;node *createNode() { // allocate a memorynode __________;temp = new node ;return _______ ;}
void insertNode(){node *temp, *traverse;int n;cout<< "Enter -1 to end "<<endl;cout<< "Enter the values to be added in list"<<endl;cin>>n;
while(n!=-1){temp = createNode(); // allocate memorytemp->data = ________;temp->next = ________;if ( ___________ == NULL){head = _________;}
else {traverse = ( );while (traverse->next != ________{traverse = traverse-> ___________;} traverse->next= temp;}
cout<<"Enter the value to be added in the list"<<endl;cin>>n;
}}
void printlist(){node *traverse = head; // if head == NULLwhile (traverse != NULL) {
cout<<traverse->data<<" ";traverse = traverse->next;}}
int main(){int option;
do{cout<<"\n =============== MAIN…
5. A linked list that stores int values would be comprised of a group of Nodes. Wemight define the Node by
A. class Node
{Node next;}B. class Node{int next;}
C. class Node
{
int data;
D. class Node
{
int data;Node next;
}
Chapter 17 Solutions
Starting Out with C++: Early Objects (9th Edition)
Ch. 17.1 - Prob. 17.1CPCh. 17.1 - Prob. 17.2CPCh. 17.1 - Prob. 17.3CPCh. 17.1 - Prob. 17.4CPCh. 17.2 - Prob. 17.5CPCh. 17.2 - Prob. 17.6CPCh. 17.2 - Why does the insertNode function shown in this...Ch. 17.2 - Prob. 17.8CPCh. 17.2 - Prob. 17.9CPCh. 17.2 - Prob. 17.10CP
Ch. 17 - Prob. 1RQECh. 17 - Prob. 2RQECh. 17 - Prob. 3RQECh. 17 - Prob. 4RQECh. 17 - Prob. 5RQECh. 17 - Prob. 6RQECh. 17 - Prob. 7RQECh. 17 - Prob. 8RQECh. 17 - Prob. 9RQECh. 17 - Write a function void printSecond(ListNode ptr}...Ch. 17 - Write a function double lastValue(ListNode ptr)...Ch. 17 - Write a function ListNode removeFirst(ListNode...Ch. 17 - Prob. 13RQECh. 17 - Prob. 14RQECh. 17 - Prob. 15RQECh. 17 - Prob. 16RQECh. 17 - Prob. 17RQECh. 17 - Prob. 18RQECh. 17 - Prob. 1PCCh. 17 - Prob. 2PCCh. 17 - Prob. 3PCCh. 17 - Prob. 4PCCh. 17 - Prob. 5PCCh. 17 - Prob. 6PCCh. 17 - Prob. 7PCCh. 17 - Prob. 8PCCh. 17 - Prob. 10PCCh. 17 - Prob. 11PCCh. 17 - Prob. 12PCCh. 17 - Running Back Program 17-11 makes a person run from...Ch. 17 - Read , Sort , Merge Using the ListNode structure...
Knowledge Booster
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.Similar questions
- Using C, Must be in C Create a menu driven program that performs the following tasks (each task is a menu item): a. Create a doubly linked list of length 5 using dynamic allocation. Your linked-list should support method Write a function on to print the content of the linked list following its order. Write a function on to reverse the doubly linked list. Write a function to Delete the first node in your doubly Linked listarrow_forwardJAVA CODE PLEASE 2. Linked List Quiz by CodeChum Admin Write a function printNodes that takes in the head of a linked list and prints all the values of that linked list using a while loop. Print the values separated by a [space]->[space] Create a program that accepts 10 integer inputs. Assign each input into a node and link them in ascending order then print the linked list. Create another two linked lists: One for nodes with even numbers and the other one for odd numbers. Print them respectively using the printNodes function. Input 1. One line containing an integer 2. One line containing an integer 3. One line containing an integer 4. One line containing an integer 5. One line containing an integer 6. One line containing an integer 7. One line containing an integer 8. One line containing an integer 9. One line containing an integer 10. One line containing an integer Output Enter·number·1:·1 Enter·number·2:·2 Enter·number·3:·3 Enter·number·4:·4…arrow_forwardİn C language A singly linear list stores integer values in each node and has multiple nodes. Write a function using given prototype below. This function cuts the first node of the list and adds it to the end as last node. It takes beginning address of the list as a parameter and returns the updated list.struct node* cutheadaddlast(struct node* head);struct node { int number; struct node * next; };arrow_forward
- struct node{int num;node *next, *before;};start 18 27 36 45 54 63 The above-linked list is made of nodes of the type struct ex. Your task is now to Write a complete function code to a. Find the sum of all the values of the node in the linked list. b. Print the values in the linked list in reverse order. Use a temporary pointer temp for a and b. i dont need a full code just the list partarrow_forwardi) Create a Node class which will hold two fields i.e an integer element and a reference to the next Node. ii) Create a Linked list Abstract Data Type (ADT)named MyList.The elements in the list are Nodes consisting of an integer type key (all keys are unique) and a reference to the next node. Use Python Language.arrow_forwardEmpty list. Inserting a node with data 5 updates which pointers? Head and tail O Tailarrow_forward
- Create two linked lists and then make a concatList(NODE **list1, NODE **list2) function that concatenates the two lists. The concatenated list must be a linked list. Fill in the "Write code here" sections appropriately.arrow_forwardLinked List Write an algorithm length to count the number of nodes in a singly linked list p, where p points to the first node in the list. The last node has link field NULL. Assume that each node has two fields: data and link. Account for the range of all possible linked list lengths.arrow_forwardC++ CODING PROBLEM WHERE I NEED CODE TO CREATE A LINKED LIST (I also put a screen shot of the problem below. Two strings, code1 and code2, are read from input as two states' codes. headObj has the default value of "code". Create a new node firstState with string code1 and insert firstState after headObj. Then, create a second node secondState with string code2 and insert secondState after firstState. Ex: If the input is MA IA, then the output is: code MA IA #include <iostream>using namespace std; class StateNode { public: StateNode(string codeInit = "", StateNode* nextLoc = nullptr); void InsertAfter(StateNode* nodeLoc); StateNode* GetNext(); void PrintNodeData(); private: string codeVal; StateNode* nextNodePtr;}; StateNode::StateNode(string codeInit, StateNode* nextLoc) { this->codeVal = codeInit; this->nextNodePtr = nextLoc;} void StateNode::InsertAfter(StateNode* nodeLoc) { StateNode* tmpNext = nullptr; tmpNext =…arrow_forward
- Data Structures and algorithms: Topic: Doubly and circular Linked Lists in java: Please solve this on urgent basis: Attach output's picture and explain every statement in commments: Implemented Circular Linked List CODE: #include <bits/stdc++.h> // include the standard c++ header fileusing namespace std; class Node // definition of the class for the node of the linked list{public: int data; Node* next;}; void push(Node** head_ref, int data) // definition of the function to insert the element in the list{ Node* ptr1 = new Node(); ptr1->data = data; ptr1->next = *head_ref; if (*head_ref != NULL) // when the head of the list does not points to null { Node* temp = *head_ref; while (temp->next != *head_ref) temp = temp->next; temp->next = ptr1; } else…arrow_forwardC++ Please help me modify this coding which need to apply a linked list to store the node. Also use a stack concept. The code: #include<iostream>#include<stdlib.h>#include<string.h> using namespace std; struct node{ char data[100]; struct node* next; }; int words = 0; // function for add values to stackstruct node* add(struct node* stack, char *str){ struct node* tp = (struct node*)malloc(sizeof(struct node)); strcpy(tp->data,str); tp->next = stack; words++; return tp; } //redo functionvoid redo(struct node* stack){ if(stack == NULL) return; words++; } //undo functionvoid undo(struct node* stack){ if(stack == NULL) return; words--; } //print functionint print(struct node* stack,int idx){ if(stack == NULL) return 0; idx = print(stack->next,idx); if(idx<words) cout<<"\n"<<stack->data; return idx+1; } //function for save in fileint save_words(FILE* filePointer, struct node*…arrow_forwarddata structure Create a Java program using a Linked list by adding 5 nodes and then removing 1 node from the list. The node entries can be either Numbers (Int) or Characters (String).arrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- Systems ArchitectureComputer ScienceISBN:9781305080195Author:Stephen D. BurdPublisher:Cengage Learning
Systems Architecture
Computer Science
ISBN:9781305080195
Author:Stephen D. Burd
Publisher:Cengage Learning