SlideShare a Scribd company logo
1 of 3
Download to read offline
I have been tasked to write a code for a Singly Linked list that includes the following: Implement
a singly linked list class with the following methods: - `void insertAtBeginning(int value)`:
Inserts a new node with the given value at the beginning of the list. - `void insertAtEnd(int
value)`: Inserts a new node with the given value at the end of the list. - `void deleteNode(int
value)`: Deletes the first occurrence of a node with the given value. - `void display()`: Displays
the elements of the linked list. I have everything EXCEPT for the deleteNode. I have it included,
but it is throwing an error....I just need a little extra help to fix that part. My Code: #
#include
using namespace std;
class Node { //user defined type.
public: // public class modifier to access the class node.
int value;
Node* next;
};
void display(Node *head) {
if(head == NULL){
cout << "NULL" << endl;
}
else {
cout << head->value << endl;
display(head->next);
}
}
void insertAtBeginning(Node**head, int newValue){
// Steps to add a Node to the beginning of the linked list
//1. Prepare a newNode
Node * newNode = new Node();
newNode ->value = newValue;
//2. Put it in front of the current head
newNode->next = *head;
//3. Move head of the list to point to the newNode
*head= newNode;
}
void insertAtEnd(Node**head, int newValue) {
//1.Prepare a newNode
Node* newNode= new Node();
newNode ->value = newValue;
newNode->next = NULL;
//2. If Linked list is empty, newNode will be a head node
if(*head ==NULL){
*head = newNode;
return;
}
//3. Find last node
Node* last= *head;
while(last->next!=NULL){
last=last->next;
}
//4. Insert newNode after last node (at the end of List)
last->next =newNode;
}
void deleteNode(Node**before_del){
Node* temp;
temp = before_del->next;
before_del->next = temp->next;
delete temp;
}
int main()
{
Node* head=new Node();
Node* second=new Node();
Node* third=new Node();
Node* fourth=new Node();
head->value = 7;
head->next = second;
second->value = 12;
second->next = third;
third->value = 15;
third->next = fourth;
fourth->value = 20;
fourth->next = NULL;
insertAtBeginning(&head, 4);
insertAtBeginning(&head, 6);
insertAtEnd(&head, 23);
del(&head(15)->next);
display(head);
}

More Related Content

Similar to I have been tasked to write a code for a Singly Linked list that inc.pdf

Create a link list. Add some nodes to it, search and delete nodes fro.pdf
Create a link list. Add some nodes to it, search and delete nodes fro.pdfCreate a link list. Add some nodes to it, search and delete nodes fro.pdf
Create a link list. Add some nodes to it, search and delete nodes fro.pdfhadpadrrajeshh
 
Describe an algorithm for concatenating two singly linked lists L and.pdf
Describe an algorithm for concatenating two singly linked lists L and.pdfDescribe an algorithm for concatenating two singly linked lists L and.pdf
Describe an algorithm for concatenating two singly linked lists L and.pdfdeepak596396
 
please help me in C++Objective Create a singly linked list of num.pdf
please help me in C++Objective Create a singly linked list of num.pdfplease help me in C++Objective Create a singly linked list of num.pdf
please help me in C++Objective Create a singly linked list of num.pdfaminbijal86
 
THE CODE HAS A SEGMENTATION FAULT BUT I CANNOT FIND OUT WHERE. NEED .pdf
THE CODE HAS A SEGMENTATION FAULT BUT I CANNOT FIND OUT WHERE. NEED .pdfTHE CODE HAS A SEGMENTATION FAULT BUT I CANNOT FIND OUT WHERE. NEED .pdf
THE CODE HAS A SEGMENTATION FAULT BUT I CANNOT FIND OUT WHERE. NEED .pdffathimahardwareelect
 
How to do insertion sort on a singly linked list with no header usin.pdf
How to do insertion sort on a singly linked list with no header usin.pdfHow to do insertion sort on a singly linked list with no header usin.pdf
How to do insertion sort on a singly linked list with no header usin.pdfarihantelehyb
 
C program to insert a node in doubly linked list
C program to insert a node in doubly linked listC program to insert a node in doubly linked list
C program to insert a node in doubly linked listSourav Gayen
 
linked List.docx vhjgvjhvgjhjhbbjkhkjhkjh
linked List.docx vhjgvjhvgjhjhbbjkhkjhkjhlinked List.docx vhjgvjhvgjhjhbbjkhkjhkjh
linked List.docx vhjgvjhvgjhjhbbjkhkjhkjhvasavim9
 
C++ Please write the whole code that is needed for this assignment- wr.docx
C++ Please write the whole code that is needed for this assignment- wr.docxC++ Please write the whole code that is needed for this assignment- wr.docx
C++ Please write the whole code that is needed for this assignment- wr.docxBrianGHiNewmanv
 
Using the provided table interface table.h and the sample linked lis.pdf
Using the provided table interface table.h and the sample linked lis.pdfUsing the provided table interface table.h and the sample linked lis.pdf
Using the provided table interface table.h and the sample linked lis.pdfconnellalykshamesb60
 
C code on linked list #include stdio.h #include stdlib.h.pdf
 C code on linked list #include stdio.h #include stdlib.h.pdf C code on linked list #include stdio.h #include stdlib.h.pdf
C code on linked list #include stdio.h #include stdlib.h.pdfdeepua8
 
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
 
package linkedLists- import java-util-Iterator- --- A class representi.pdf
package linkedLists- import java-util-Iterator- --- A class representi.pdfpackage linkedLists- import java-util-Iterator- --- A class representi.pdf
package linkedLists- import java-util-Iterator- --- A class representi.pdfarcellzone
 
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
 
1#include stdio.h#include stdlib.h#include assert.h .pdf
1#include stdio.h#include stdlib.h#include assert.h .pdf1#include stdio.h#include stdlib.h#include assert.h .pdf
1#include stdio.h#include stdlib.h#include assert.h .pdfsudhinjv
 
Program to insert in a sorted list #includestdio.h#include.pdf
 Program to insert in a sorted list #includestdio.h#include.pdf Program to insert in a sorted list #includestdio.h#include.pdf
Program to insert in a sorted list #includestdio.h#include.pdfsudhirchourasia86
 
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
 
C++Write a method Node Nodereverse() which reverses a list..pdf
C++Write a method Node Nodereverse() which reverses a list..pdfC++Write a method Node Nodereverse() which reverses a list..pdf
C++Write a method Node Nodereverse() which reverses a list..pdfarjunenterprises1978
 
Lec-4_Linked-List (1).pdf
Lec-4_Linked-List (1).pdfLec-4_Linked-List (1).pdf
Lec-4_Linked-List (1).pdfKylaMaeGarcia1
 

Similar to I have been tasked to write a code for a Singly Linked list that inc.pdf (20)

Create a link list. Add some nodes to it, search and delete nodes fro.pdf
Create a link list. Add some nodes to it, search and delete nodes fro.pdfCreate a link list. Add some nodes to it, search and delete nodes fro.pdf
Create a link list. Add some nodes to it, search and delete nodes fro.pdf
 
Describe an algorithm for concatenating two singly linked lists L and.pdf
Describe an algorithm for concatenating two singly linked lists L and.pdfDescribe an algorithm for concatenating two singly linked lists L and.pdf
Describe an algorithm for concatenating two singly linked lists L and.pdf
 
please help me in C++Objective Create a singly linked list of num.pdf
please help me in C++Objective Create a singly linked list of num.pdfplease help me in C++Objective Create a singly linked list of num.pdf
please help me in C++Objective Create a singly linked list of num.pdf
 
THE CODE HAS A SEGMENTATION FAULT BUT I CANNOT FIND OUT WHERE. NEED .pdf
THE CODE HAS A SEGMENTATION FAULT BUT I CANNOT FIND OUT WHERE. NEED .pdfTHE CODE HAS A SEGMENTATION FAULT BUT I CANNOT FIND OUT WHERE. NEED .pdf
THE CODE HAS A SEGMENTATION FAULT BUT I CANNOT FIND OUT WHERE. NEED .pdf
 
How to do insertion sort on a singly linked list with no header usin.pdf
How to do insertion sort on a singly linked list with no header usin.pdfHow to do insertion sort on a singly linked list with no header usin.pdf
How to do insertion sort on a singly linked list with no header usin.pdf
 
C program to insert a node in doubly linked list
C program to insert a node in doubly linked listC program to insert a node in doubly linked list
C program to insert a node in doubly linked list
 
C Homework Help
C Homework HelpC Homework Help
C Homework Help
 
linked List.docx vhjgvjhvgjhjhbbjkhkjhkjh
linked List.docx vhjgvjhvgjhjhbbjkhkjhkjhlinked List.docx vhjgvjhvgjhjhbbjkhkjhkjh
linked List.docx vhjgvjhvgjhjhbbjkhkjhkjh
 
C++ Please write the whole code that is needed for this assignment- wr.docx
C++ Please write the whole code that is needed for this assignment- wr.docxC++ Please write the whole code that is needed for this assignment- wr.docx
C++ Please write the whole code that is needed for this assignment- wr.docx
 
Using the provided table interface table.h and the sample linked lis.pdf
Using the provided table interface table.h and the sample linked lis.pdfUsing the provided table interface table.h and the sample linked lis.pdf
Using the provided table interface table.h and the sample linked lis.pdf
 
DSA(1).pptx
DSA(1).pptxDSA(1).pptx
DSA(1).pptx
 
C code on linked list #include stdio.h #include stdlib.h.pdf
 C code on linked list #include stdio.h #include stdlib.h.pdf C code on linked list #include stdio.h #include stdlib.h.pdf
C code on linked list #include stdio.h #include stdlib.h.pdf
 
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
 
package linkedLists- import java-util-Iterator- --- A class representi.pdf
package linkedLists- import java-util-Iterator- --- A class representi.pdfpackage linkedLists- import java-util-Iterator- --- A class representi.pdf
package linkedLists- import java-util-Iterator- --- A class representi.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
 
1#include stdio.h#include stdlib.h#include assert.h .pdf
1#include stdio.h#include stdlib.h#include assert.h .pdf1#include stdio.h#include stdlib.h#include assert.h .pdf
1#include stdio.h#include stdlib.h#include assert.h .pdf
 
Program to insert in a sorted list #includestdio.h#include.pdf
 Program to insert in a sorted list #includestdio.h#include.pdf Program to insert in a sorted list #includestdio.h#include.pdf
Program to insert in a sorted list #includestdio.h#include.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
 
C++Write a method Node Nodereverse() which reverses a list..pdf
C++Write a method Node Nodereverse() which reverses a list..pdfC++Write a method Node Nodereverse() which reverses a list..pdf
C++Write a method Node Nodereverse() which reverses a list..pdf
 
Lec-4_Linked-List (1).pdf
Lec-4_Linked-List (1).pdfLec-4_Linked-List (1).pdf
Lec-4_Linked-List (1).pdf
 

More from arkmuzikllc

Here is selection filepublic class Selection { public static in.pdf
Here is selection filepublic class Selection {  public static in.pdfHere is selection filepublic class Selection {  public static in.pdf
Here is selection filepublic class Selection { public static in.pdfarkmuzikllc
 
Help me with these multiple-choice questions. Please dont use chat .pdf
Help me with these multiple-choice questions. Please dont use chat .pdfHelp me with these multiple-choice questions. Please dont use chat .pdf
Help me with these multiple-choice questions. Please dont use chat .pdfarkmuzikllc
 
Hello I am stuck in my code I know is everything is goid but I think.pdf
Hello I am stuck in my code I know is everything is goid but I think.pdfHello I am stuck in my code I know is everything is goid but I think.pdf
Hello I am stuck in my code I know is everything is goid but I think.pdfarkmuzikllc
 
HeadWallRam Inc. has expanded its reach globally and needs to re-lay.pdf
HeadWallRam Inc. has expanded its reach globally and needs to re-lay.pdfHeadWallRam Inc. has expanded its reach globally and needs to re-lay.pdf
HeadWallRam Inc. has expanded its reach globally and needs to re-lay.pdfarkmuzikllc
 
HINT For i = 1 , . . . ,n, let S[i] be the max sum ending with A[i].pdf
HINT For i = 1 , . . . ,n, let S[i] be the max sum ending with A[i].pdfHINT For i = 1 , . . . ,n, let S[i] be the max sum ending with A[i].pdf
HINT For i = 1 , . . . ,n, let S[i] be the max sum ending with A[i].pdfarkmuzikllc
 
Hi, I need some assistance with this UML use case diagram. I manage .pdf
Hi, I need some assistance with this UML use case diagram. I manage .pdfHi, I need some assistance with this UML use case diagram. I manage .pdf
Hi, I need some assistance with this UML use case diagram. I manage .pdfarkmuzikllc
 
Give an NFA that recognizes the language (10 + 110 + 101) and then .pdf
Give an NFA that recognizes the language (10 + 110 + 101) and then .pdfGive an NFA that recognizes the language (10 + 110 + 101) and then .pdf
Give an NFA that recognizes the language (10 + 110 + 101) and then .pdfarkmuzikllc
 
IN JAVA BJP5 Exercise 6.19 leetSpeak LanguageType Java file pr.pdf
IN JAVA BJP5 Exercise 6.19 leetSpeak LanguageType  Java file pr.pdfIN JAVA BJP5 Exercise 6.19 leetSpeak LanguageType  Java file pr.pdf
IN JAVA BJP5 Exercise 6.19 leetSpeak LanguageType Java file pr.pdfarkmuzikllc
 
Goal Create a hypothetical threat assessment based on vulnerabilities.pdf
Goal Create a hypothetical threat assessment based on vulnerabilities.pdfGoal Create a hypothetical threat assessment based on vulnerabilities.pdf
Goal Create a hypothetical threat assessment based on vulnerabilities.pdfarkmuzikllc
 
import React, { useEffect } from react;import { BrowserRouter as.pdf
import React, { useEffect } from react;import { BrowserRouter as.pdfimport React, { useEffect } from react;import { BrowserRouter as.pdf
import React, { useEffect } from react;import { BrowserRouter as.pdfarkmuzikllc
 
im solving tha m-puzzel sliding tail problem where m = n^2 - 1 I ha.pdf
im solving tha m-puzzel sliding tail problem where m = n^2 - 1 I ha.pdfim solving tha m-puzzel sliding tail problem where m = n^2 - 1 I ha.pdf
im solving tha m-puzzel sliding tail problem where m = n^2 - 1 I ha.pdfarkmuzikllc
 
Im creating a skip list program for my Algorithms and Advanced Data.pdf
Im creating a skip list program for my Algorithms and Advanced Data.pdfIm creating a skip list program for my Algorithms and Advanced Data.pdf
Im creating a skip list program for my Algorithms and Advanced Data.pdfarkmuzikllc
 
if any additional information is required let me know Work through t.pdf
if any additional information is required let me know Work through t.pdfif any additional information is required let me know Work through t.pdf
if any additional information is required let me know Work through t.pdfarkmuzikllc
 
I need help with providing a 2 page overview of the case study provi.pdf
I need help with providing a 2 page overview of the case study provi.pdfI need help with providing a 2 page overview of the case study provi.pdf
I need help with providing a 2 page overview of the case study provi.pdfarkmuzikllc
 
I keep getting NullPointerExcepetion, can someone help me with spinL.pdf
I keep getting NullPointerExcepetion, can someone help me with spinL.pdfI keep getting NullPointerExcepetion, can someone help me with spinL.pdf
I keep getting NullPointerExcepetion, can someone help me with spinL.pdfarkmuzikllc
 
I am trying to pass a date to a function in postgres.My function w.pdf
I am trying to pass a date to a function in postgres.My function w.pdfI am trying to pass a date to a function in postgres.My function w.pdf
I am trying to pass a date to a function in postgres.My function w.pdfarkmuzikllc
 
How can an event such as the terrorist attacks of September 2001 aff.pdf
How can an event such as the terrorist attacks of September 2001 aff.pdfHow can an event such as the terrorist attacks of September 2001 aff.pdf
How can an event such as the terrorist attacks of September 2001 aff.pdfarkmuzikllc
 
Hey! Could I possibly get some help with this Its a little confusi.pdf
Hey! Could I possibly get some help with this Its a little confusi.pdfHey! Could I possibly get some help with this Its a little confusi.pdf
Hey! Could I possibly get some help with this Its a little confusi.pdfarkmuzikllc
 

More from arkmuzikllc (18)

Here is selection filepublic class Selection { public static in.pdf
Here is selection filepublic class Selection {  public static in.pdfHere is selection filepublic class Selection {  public static in.pdf
Here is selection filepublic class Selection { public static in.pdf
 
Help me with these multiple-choice questions. Please dont use chat .pdf
Help me with these multiple-choice questions. Please dont use chat .pdfHelp me with these multiple-choice questions. Please dont use chat .pdf
Help me with these multiple-choice questions. Please dont use chat .pdf
 
Hello I am stuck in my code I know is everything is goid but I think.pdf
Hello I am stuck in my code I know is everything is goid but I think.pdfHello I am stuck in my code I know is everything is goid but I think.pdf
Hello I am stuck in my code I know is everything is goid but I think.pdf
 
HeadWallRam Inc. has expanded its reach globally and needs to re-lay.pdf
HeadWallRam Inc. has expanded its reach globally and needs to re-lay.pdfHeadWallRam Inc. has expanded its reach globally and needs to re-lay.pdf
HeadWallRam Inc. has expanded its reach globally and needs to re-lay.pdf
 
HINT For i = 1 , . . . ,n, let S[i] be the max sum ending with A[i].pdf
HINT For i = 1 , . . . ,n, let S[i] be the max sum ending with A[i].pdfHINT For i = 1 , . . . ,n, let S[i] be the max sum ending with A[i].pdf
HINT For i = 1 , . . . ,n, let S[i] be the max sum ending with A[i].pdf
 
Hi, I need some assistance with this UML use case diagram. I manage .pdf
Hi, I need some assistance with this UML use case diagram. I manage .pdfHi, I need some assistance with this UML use case diagram. I manage .pdf
Hi, I need some assistance with this UML use case diagram. I manage .pdf
 
Give an NFA that recognizes the language (10 + 110 + 101) and then .pdf
Give an NFA that recognizes the language (10 + 110 + 101) and then .pdfGive an NFA that recognizes the language (10 + 110 + 101) and then .pdf
Give an NFA that recognizes the language (10 + 110 + 101) and then .pdf
 
IN JAVA BJP5 Exercise 6.19 leetSpeak LanguageType Java file pr.pdf
IN JAVA BJP5 Exercise 6.19 leetSpeak LanguageType  Java file pr.pdfIN JAVA BJP5 Exercise 6.19 leetSpeak LanguageType  Java file pr.pdf
IN JAVA BJP5 Exercise 6.19 leetSpeak LanguageType Java file pr.pdf
 
Goal Create a hypothetical threat assessment based on vulnerabilities.pdf
Goal Create a hypothetical threat assessment based on vulnerabilities.pdfGoal Create a hypothetical threat assessment based on vulnerabilities.pdf
Goal Create a hypothetical threat assessment based on vulnerabilities.pdf
 
import React, { useEffect } from react;import { BrowserRouter as.pdf
import React, { useEffect } from react;import { BrowserRouter as.pdfimport React, { useEffect } from react;import { BrowserRouter as.pdf
import React, { useEffect } from react;import { BrowserRouter as.pdf
 
im solving tha m-puzzel sliding tail problem where m = n^2 - 1 I ha.pdf
im solving tha m-puzzel sliding tail problem where m = n^2 - 1 I ha.pdfim solving tha m-puzzel sliding tail problem where m = n^2 - 1 I ha.pdf
im solving tha m-puzzel sliding tail problem where m = n^2 - 1 I ha.pdf
 
Im creating a skip list program for my Algorithms and Advanced Data.pdf
Im creating a skip list program for my Algorithms and Advanced Data.pdfIm creating a skip list program for my Algorithms and Advanced Data.pdf
Im creating a skip list program for my Algorithms and Advanced Data.pdf
 
if any additional information is required let me know Work through t.pdf
if any additional information is required let me know Work through t.pdfif any additional information is required let me know Work through t.pdf
if any additional information is required let me know Work through t.pdf
 
I need help with providing a 2 page overview of the case study provi.pdf
I need help with providing a 2 page overview of the case study provi.pdfI need help with providing a 2 page overview of the case study provi.pdf
I need help with providing a 2 page overview of the case study provi.pdf
 
I keep getting NullPointerExcepetion, can someone help me with spinL.pdf
I keep getting NullPointerExcepetion, can someone help me with spinL.pdfI keep getting NullPointerExcepetion, can someone help me with spinL.pdf
I keep getting NullPointerExcepetion, can someone help me with spinL.pdf
 
I am trying to pass a date to a function in postgres.My function w.pdf
I am trying to pass a date to a function in postgres.My function w.pdfI am trying to pass a date to a function in postgres.My function w.pdf
I am trying to pass a date to a function in postgres.My function w.pdf
 
How can an event such as the terrorist attacks of September 2001 aff.pdf
How can an event such as the terrorist attacks of September 2001 aff.pdfHow can an event such as the terrorist attacks of September 2001 aff.pdf
How can an event such as the terrorist attacks of September 2001 aff.pdf
 
Hey! Could I possibly get some help with this Its a little confusi.pdf
Hey! Could I possibly get some help with this Its a little confusi.pdfHey! Could I possibly get some help with this Its a little confusi.pdf
Hey! Could I possibly get some help with this Its a little confusi.pdf
 

Recently uploaded

An Overview of the Odoo 17 Knowledge App
An Overview of the Odoo 17 Knowledge AppAn Overview of the Odoo 17 Knowledge App
An Overview of the Odoo 17 Knowledge AppCeline George
 
Graduate Outcomes Presentation Slides - English (v3).pptx
Graduate Outcomes Presentation Slides - English (v3).pptxGraduate Outcomes Presentation Slides - English (v3).pptx
Graduate Outcomes Presentation Slides - English (v3).pptxneillewis46
 
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...Nguyen Thanh Tu Collection
 
ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...
ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...
ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...Nguyen Thanh Tu Collection
 
DEMONSTRATION LESSON IN ENGLISH 4 MATATAG CURRICULUM
DEMONSTRATION LESSON IN ENGLISH 4 MATATAG CURRICULUMDEMONSTRATION LESSON IN ENGLISH 4 MATATAG CURRICULUM
DEMONSTRATION LESSON IN ENGLISH 4 MATATAG CURRICULUMELOISARIVERA8
 
male presentation...pdf.................
male presentation...pdf.................male presentation...pdf.................
male presentation...pdf.................MirzaAbrarBaig5
 
MOOD STABLIZERS DRUGS.pptx
MOOD     STABLIZERS           DRUGS.pptxMOOD     STABLIZERS           DRUGS.pptx
MOOD STABLIZERS DRUGS.pptxPoojaSen20
 
Andreas Schleicher presents at the launch of What does child empowerment mean...
Andreas Schleicher presents at the launch of What does child empowerment mean...Andreas Schleicher presents at the launch of What does child empowerment mean...
Andreas Schleicher presents at the launch of What does child empowerment mean...EduSkills OECD
 
8 Tips for Effective Working Capital Management
8 Tips for Effective Working Capital Management8 Tips for Effective Working Capital Management
8 Tips for Effective Working Capital ManagementMBA Assignment Experts
 
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...Nguyen Thanh Tu Collection
 
Spellings Wk 4 and Wk 5 for Grade 4 at CAPS
Spellings Wk 4 and Wk 5 for Grade 4 at CAPSSpellings Wk 4 and Wk 5 for Grade 4 at CAPS
Spellings Wk 4 and Wk 5 for Grade 4 at CAPSAnaAcapella
 
How to Manage Website in Odoo 17 Studio App.pptx
How to Manage Website in Odoo 17 Studio App.pptxHow to Manage Website in Odoo 17 Studio App.pptx
How to Manage Website in Odoo 17 Studio App.pptxCeline George
 
How to Send Pro Forma Invoice to Your Customers in Odoo 17
How to Send Pro Forma Invoice to Your Customers in Odoo 17How to Send Pro Forma Invoice to Your Customers in Odoo 17
How to Send Pro Forma Invoice to Your Customers in Odoo 17Celine George
 
How To Create Editable Tree View in Odoo 17
How To Create Editable Tree View in Odoo 17How To Create Editable Tree View in Odoo 17
How To Create Editable Tree View in Odoo 17Celine George
 
SPLICE Working Group: Reusable Code Examples
SPLICE Working Group:Reusable Code ExamplesSPLICE Working Group:Reusable Code Examples
SPLICE Working Group: Reusable Code ExamplesPeter Brusilovsky
 
UChicago CMSC 23320 - The Best Commit Messages of 2024
UChicago CMSC 23320 - The Best Commit Messages of 2024UChicago CMSC 23320 - The Best Commit Messages of 2024
UChicago CMSC 23320 - The Best Commit Messages of 2024Borja Sotomayor
 
Sternal Fractures & Dislocations - EMGuidewire Radiology Reading Room
Sternal Fractures & Dislocations - EMGuidewire Radiology Reading RoomSternal Fractures & Dislocations - EMGuidewire Radiology Reading Room
Sternal Fractures & Dislocations - EMGuidewire Radiology Reading RoomSean M. Fox
 

Recently uploaded (20)

An Overview of the Odoo 17 Knowledge App
An Overview of the Odoo 17 Knowledge AppAn Overview of the Odoo 17 Knowledge App
An Overview of the Odoo 17 Knowledge App
 
Mattingly "AI and Prompt Design: LLMs with NER"
Mattingly "AI and Prompt Design: LLMs with NER"Mattingly "AI and Prompt Design: LLMs with NER"
Mattingly "AI and Prompt Design: LLMs with NER"
 
Graduate Outcomes Presentation Slides - English (v3).pptx
Graduate Outcomes Presentation Slides - English (v3).pptxGraduate Outcomes Presentation Slides - English (v3).pptx
Graduate Outcomes Presentation Slides - English (v3).pptx
 
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...
 
ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...
ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...
ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...
 
DEMONSTRATION LESSON IN ENGLISH 4 MATATAG CURRICULUM
DEMONSTRATION LESSON IN ENGLISH 4 MATATAG CURRICULUMDEMONSTRATION LESSON IN ENGLISH 4 MATATAG CURRICULUM
DEMONSTRATION LESSON IN ENGLISH 4 MATATAG CURRICULUM
 
male presentation...pdf.................
male presentation...pdf.................male presentation...pdf.................
male presentation...pdf.................
 
MOOD STABLIZERS DRUGS.pptx
MOOD     STABLIZERS           DRUGS.pptxMOOD     STABLIZERS           DRUGS.pptx
MOOD STABLIZERS DRUGS.pptx
 
Andreas Schleicher presents at the launch of What does child empowerment mean...
Andreas Schleicher presents at the launch of What does child empowerment mean...Andreas Schleicher presents at the launch of What does child empowerment mean...
Andreas Schleicher presents at the launch of What does child empowerment mean...
 
Including Mental Health Support in Project Delivery, 14 May.pdf
Including Mental Health Support in Project Delivery, 14 May.pdfIncluding Mental Health Support in Project Delivery, 14 May.pdf
Including Mental Health Support in Project Delivery, 14 May.pdf
 
8 Tips for Effective Working Capital Management
8 Tips for Effective Working Capital Management8 Tips for Effective Working Capital Management
8 Tips for Effective Working Capital Management
 
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...
 
Spellings Wk 4 and Wk 5 for Grade 4 at CAPS
Spellings Wk 4 and Wk 5 for Grade 4 at CAPSSpellings Wk 4 and Wk 5 for Grade 4 at CAPS
Spellings Wk 4 and Wk 5 for Grade 4 at CAPS
 
How to Manage Website in Odoo 17 Studio App.pptx
How to Manage Website in Odoo 17 Studio App.pptxHow to Manage Website in Odoo 17 Studio App.pptx
How to Manage Website in Odoo 17 Studio App.pptx
 
How to Send Pro Forma Invoice to Your Customers in Odoo 17
How to Send Pro Forma Invoice to Your Customers in Odoo 17How to Send Pro Forma Invoice to Your Customers in Odoo 17
How to Send Pro Forma Invoice to Your Customers in Odoo 17
 
How To Create Editable Tree View in Odoo 17
How To Create Editable Tree View in Odoo 17How To Create Editable Tree View in Odoo 17
How To Create Editable Tree View in Odoo 17
 
SPLICE Working Group: Reusable Code Examples
SPLICE Working Group:Reusable Code ExamplesSPLICE Working Group:Reusable Code Examples
SPLICE Working Group: Reusable Code Examples
 
UChicago CMSC 23320 - The Best Commit Messages of 2024
UChicago CMSC 23320 - The Best Commit Messages of 2024UChicago CMSC 23320 - The Best Commit Messages of 2024
UChicago CMSC 23320 - The Best Commit Messages of 2024
 
VAMOS CUIDAR DO NOSSO PLANETA! .
VAMOS CUIDAR DO NOSSO PLANETA!                    .VAMOS CUIDAR DO NOSSO PLANETA!                    .
VAMOS CUIDAR DO NOSSO PLANETA! .
 
Sternal Fractures & Dislocations - EMGuidewire Radiology Reading Room
Sternal Fractures & Dislocations - EMGuidewire Radiology Reading RoomSternal Fractures & Dislocations - EMGuidewire Radiology Reading Room
Sternal Fractures & Dislocations - EMGuidewire Radiology Reading Room
 

I have been tasked to write a code for a Singly Linked list that inc.pdf

  • 1. I have been tasked to write a code for a Singly Linked list that includes the following: Implement a singly linked list class with the following methods: - `void insertAtBeginning(int value)`: Inserts a new node with the given value at the beginning of the list. - `void insertAtEnd(int value)`: Inserts a new node with the given value at the end of the list. - `void deleteNode(int value)`: Deletes the first occurrence of a node with the given value. - `void display()`: Displays the elements of the linked list. I have everything EXCEPT for the deleteNode. I have it included, but it is throwing an error....I just need a little extra help to fix that part. My Code: # #include using namespace std; class Node { //user defined type. public: // public class modifier to access the class node. int value; Node* next; }; void display(Node *head) { if(head == NULL){ cout << "NULL" << endl; } else { cout << head->value << endl; display(head->next); } } void insertAtBeginning(Node**head, int newValue){ // Steps to add a Node to the beginning of the linked list //1. Prepare a newNode Node * newNode = new Node(); newNode ->value = newValue; //2. Put it in front of the current head newNode->next = *head; //3. Move head of the list to point to the newNode *head= newNode; } void insertAtEnd(Node**head, int newValue) {
  • 2. //1.Prepare a newNode Node* newNode= new Node(); newNode ->value = newValue; newNode->next = NULL; //2. If Linked list is empty, newNode will be a head node if(*head ==NULL){ *head = newNode; return; } //3. Find last node Node* last= *head; while(last->next!=NULL){ last=last->next; } //4. Insert newNode after last node (at the end of List) last->next =newNode; } void deleteNode(Node**before_del){ Node* temp; temp = before_del->next; before_del->next = temp->next; delete temp; } int main() { Node* head=new Node(); Node* second=new Node(); Node* third=new Node(); Node* fourth=new Node(); head->value = 7; head->next = second; second->value = 12; second->next = third; third->value = 15; third->next = fourth;
  • 3. fourth->value = 20; fourth->next = NULL; insertAtBeginning(&head, 4); insertAtBeginning(&head, 6); insertAtEnd(&head, 23); del(&head(15)->next); display(head); }