SlideShare a Scribd company logo
1 of 5
Download to read offline
Write an algorithm that reads a list of integers from the keyboard, creates
a list of them using linked list implementation, and prints the result
Solution
/*
Algorithm:
Implementation of linked list.
Create a node type class which will hold an integer and next pointer to point to another node.
Create a constructor which will construct an object of type node with the integer type data as the
only parameter
and initializing next pointer to NULL.
Create LinkedList class which will only have head pointer.
Create a constructor which will initialize this head pointer to NULL.
Create a append method which will recieve an input of type integer from the user and append it
to LinkedList
using below steps:
1.Create a Node type object.
1.IF head is NULL assign a Node type object created in 1st step.
2.IF head is not NULL then traverse to the end of the linked list till you found a Node which has
next pointer
set to NULL.
3.Add Node type object created in first step to the next pointer of last node.
Create a print method which will traverse the list from the head of the linked list to the last
node(Node
with next pointer NULL) and while traversing it will keep printing the node data.
Get the userinput:
Ask user for integer continously till user input -1 and append all the integers to the linked list.
*/
PROGRAM:
#include
using namespace std;
class Node
{
public:
int data;
Node *next;
Node(int data)
{
this->data = data;
this->next = NULL;
}
};
class LinkedList
{
private:
Node *head;
public:
LinkedList()
{
head = NULL;
}
void addToFront(int data)
{
Node *temp = new Node(data);
if(head == NULL)
head = temp;
else
{
temp->next = head;
head = temp;
}
}
void append(int data)
{
Node *temp = new Node(data);
Node *current = head;
if(current == NULL)
{
head = temp;
return;
}
while(current->next != NULL)
{
current = current->next;
}
current->next = temp;
}
void print()
{
Node *current = head;
if(current == NULL)
cout << "No element in list.  ";
while(current != NULL)
{
cout << current->data << " ";
current = current->next;
}
cout << endl;
}
void deleteLinkedList()
{
Node *prev;
Node *current = head;
while(current!=NULL)
{
prev = current;
current = current->next;
delete prev;
}
}
void deleteLastNode()
{
Node *current = head;
Node *prev = NULL;
if(current == NULL)
return;
while(current->next != NULL)
{
prev = current;
current = current->next;
}
if(prev == NULL)
{
delete current;
head = NULL;
}
else
{
prev->next = NULL;
delete current;
}
}
~LinkedList()
{
deleteLinkedList();
}
};
int main()
{
LinkedList list;
int data;
while(1)
{
cout << "Enter the integer(-1 to Quit) : ";
cin >> data;
if(data==-1)
break;
list.append(data);
}
cout << "Content of LinkedList is : ";
list.print();
return 0;
}
OUTPUT:
Enter the integer(-1 to Quit) : 1
Enter the integer(-1 to Quit) : 2
Enter the integer(-1 to Quit) : 3
Enter the integer(-1 to Quit) : 4
Enter the integer(-1 to Quit) : -1
Content of LinkedList is : 1 2 3 4

More Related Content

Similar to Write an algorithm that reads a list of integers from the keyboard, .pdf

C++ Doubly-Linked ListsThe goal of the exercise is to implement a.pdf
C++ Doubly-Linked ListsThe goal of the exercise is to implement a.pdfC++ Doubly-Linked ListsThe goal of the exercise is to implement a.pdf
C++ Doubly-Linked ListsThe goal of the exercise is to implement a.pdfpoblettesedanoree498
 
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
 
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
 
Lec-4_Linked-List (1).pdf
Lec-4_Linked-List (1).pdfLec-4_Linked-List (1).pdf
Lec-4_Linked-List (1).pdfKylaMaeGarcia1
 
Write a Java Class to Implement a Generic Linked ListYour list mus.pdf
Write a Java Class to Implement a Generic Linked ListYour list mus.pdfWrite a Java Class to Implement a Generic Linked ListYour list mus.pdf
Write a Java Class to Implement a Generic Linked ListYour list mus.pdfrozakashif85
 
C++ problemPart 1 Recursive Print (40 pts)Please write the recu.pdf
C++ problemPart 1 Recursive Print (40 pts)Please write the recu.pdfC++ problemPart 1 Recursive Print (40 pts)Please write the recu.pdf
C++ problemPart 1 Recursive Print (40 pts)Please write the recu.pdfcallawaycorb73779
 
C++ Please test your program before you submit the answer.pdf
C++ Please test your program before you submit the answer.pdfC++ Please test your program before you submit the answer.pdf
C++ Please test your program before you submit the answer.pdfaashisha5
 
Assignment isPage 349-350 #4 and #5 Use the Linked List lab.pdf
Assignment isPage 349-350 #4 and #5 Use the Linked List lab.pdfAssignment isPage 349-350 #4 and #5 Use the Linked List lab.pdf
Assignment isPage 349-350 #4 and #5 Use the Linked List lab.pdffortmdu
 
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
 
File Type cppAdd the following to your linked list of strings pro.pdf
File Type cppAdd the following to your linked list of strings pro.pdfFile Type cppAdd the following to your linked list of strings pro.pdf
File Type cppAdd the following to your linked list of strings pro.pdffootworld1
 
Java AssignmentUsing the ListNode.java file below Write method.pdf
Java AssignmentUsing the ListNode.java file below Write method.pdfJava AssignmentUsing the ListNode.java file below Write method.pdf
Java AssignmentUsing the ListNode.java file below Write method.pdfambersushil
 
Mi 103 linked list
Mi 103 linked listMi 103 linked list
Mi 103 linked listAmit Vats
 
C++ please put everthing after you answer it- thanks Complete the stub.docx
C++ please put everthing after you answer it- thanks Complete the stub.docxC++ please put everthing after you answer it- thanks Complete the stub.docx
C++ please put everthing after you answer it- thanks Complete the stub.docxMatthPYNashd
 
Assignment is Page 349-350 #4 and #5 Use the Linked Lis.pdf
Assignment is Page 349-350 #4 and #5 Use the Linked Lis.pdfAssignment is Page 349-350 #4 and #5 Use the Linked Lis.pdf
Assignment is Page 349-350 #4 and #5 Use the Linked Lis.pdfformicreation
 

Similar to Write an algorithm that reads a list of integers from the keyboard, .pdf (20)

C++ Doubly-Linked ListsThe goal of the exercise is to implement a.pdf
C++ Doubly-Linked ListsThe goal of the exercise is to implement a.pdfC++ Doubly-Linked ListsThe goal of the exercise is to implement a.pdf
C++ Doubly-Linked ListsThe goal of the exercise is to implement a.pdf
 
C Homework Help
C Homework HelpC Homework Help
C Homework Help
 
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
 
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
 
Lec-4_Linked-List (1).pdf
Lec-4_Linked-List (1).pdfLec-4_Linked-List (1).pdf
Lec-4_Linked-List (1).pdf
 
Write a Java Class to Implement a Generic Linked ListYour list mus.pdf
Write a Java Class to Implement a Generic Linked ListYour list mus.pdfWrite a Java Class to Implement a Generic Linked ListYour list mus.pdf
Write a Java Class to Implement a Generic Linked ListYour list mus.pdf
 
Linkedlist
LinkedlistLinkedlist
Linkedlist
 
C++ problemPart 1 Recursive Print (40 pts)Please write the recu.pdf
C++ problemPart 1 Recursive Print (40 pts)Please write the recu.pdfC++ problemPart 1 Recursive Print (40 pts)Please write the recu.pdf
C++ problemPart 1 Recursive Print (40 pts)Please write the recu.pdf
 
Unit7 C
Unit7 CUnit7 C
Unit7 C
 
C++ Please test your program before you submit the answer.pdf
C++ Please test your program before you submit the answer.pdfC++ Please test your program before you submit the answer.pdf
C++ Please test your program before you submit the answer.pdf
 
Assignment isPage 349-350 #4 and #5 Use the Linked List lab.pdf
Assignment isPage 349-350 #4 and #5 Use the Linked List lab.pdfAssignment isPage 349-350 #4 and #5 Use the Linked List lab.pdf
Assignment isPage 349-350 #4 and #5 Use the Linked List lab.pdf
 
Lec3-Linked list.pptx
Lec3-Linked list.pptxLec3-Linked list.pptx
Lec3-Linked list.pptx
 
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
 
17 linkedlist (1)
17 linkedlist (1)17 linkedlist (1)
17 linkedlist (1)
 
File Type cppAdd the following to your linked list of strings pro.pdf
File Type cppAdd the following to your linked list of strings pro.pdfFile Type cppAdd the following to your linked list of strings pro.pdf
File Type cppAdd the following to your linked list of strings pro.pdf
 
Java AssignmentUsing the ListNode.java file below Write method.pdf
Java AssignmentUsing the ListNode.java file below Write method.pdfJava AssignmentUsing the ListNode.java file below Write method.pdf
Java AssignmentUsing the ListNode.java file below Write method.pdf
 
Mi 103 linked list
Mi 103 linked listMi 103 linked list
Mi 103 linked list
 
Linked list
Linked listLinked list
Linked list
 
C++ please put everthing after you answer it- thanks Complete the stub.docx
C++ please put everthing after you answer it- thanks Complete the stub.docxC++ please put everthing after you answer it- thanks Complete the stub.docx
C++ please put everthing after you answer it- thanks Complete the stub.docx
 
Assignment is Page 349-350 #4 and #5 Use the Linked Lis.pdf
Assignment is Page 349-350 #4 and #5 Use the Linked Lis.pdfAssignment is Page 349-350 #4 and #5 Use the Linked Lis.pdf
Assignment is Page 349-350 #4 and #5 Use the Linked Lis.pdf
 

More from Arrowdeepak

Firefly luciferase is a commonly used reporter gene. The gene origina.pdf
Firefly luciferase is a commonly used reporter gene. The gene origina.pdfFirefly luciferase is a commonly used reporter gene. The gene origina.pdf
Firefly luciferase is a commonly used reporter gene. The gene origina.pdfArrowdeepak
 
Find all hazards in this circuit. Redesign the circuit as a three-le.pdf
Find all hazards in this circuit.  Redesign the circuit as a three-le.pdfFind all hazards in this circuit.  Redesign the circuit as a three-le.pdf
Find all hazards in this circuit. Redesign the circuit as a three-le.pdfArrowdeepak
 
Fergie has the choice between investing in State of New York bond at.pdf
Fergie has the choice between investing in State of New York bond at.pdfFergie has the choice between investing in State of New York bond at.pdf
Fergie has the choice between investing in State of New York bond at.pdfArrowdeepak
 
Explain the “life” of a secreted protein molecule - trace the pathwa.pdf
Explain the “life” of a secreted protein molecule - trace the pathwa.pdfExplain the “life” of a secreted protein molecule - trace the pathwa.pdf
Explain the “life” of a secreted protein molecule - trace the pathwa.pdfArrowdeepak
 
7. Using to Table 1 to assist you, explain the rational for the diver.pdf
7. Using to Table 1 to assist you, explain the rational for the diver.pdf7. Using to Table 1 to assist you, explain the rational for the diver.pdf
7. Using to Table 1 to assist you, explain the rational for the diver.pdfArrowdeepak
 
A. list two vertebrae that spinal nerve t12 travels between .pdf
A. list two vertebrae that spinal nerve t12 travels between .pdfA. list two vertebrae that spinal nerve t12 travels between .pdf
A. list two vertebrae that spinal nerve t12 travels between .pdfArrowdeepak
 
Do people from different cultures experience emotions differently O.pdf
Do people from different cultures experience emotions differently O.pdfDo people from different cultures experience emotions differently O.pdf
Do people from different cultures experience emotions differently O.pdfArrowdeepak
 
Describe the basic elements found in robot controllers. (Choose all t.pdf
Describe the basic elements found in robot controllers. (Choose all t.pdfDescribe the basic elements found in robot controllers. (Choose all t.pdf
Describe the basic elements found in robot controllers. (Choose all t.pdfArrowdeepak
 
Consider the following probability distribution The Normal distribut.pdf
Consider the following probability distribution  The Normal distribut.pdfConsider the following probability distribution  The Normal distribut.pdf
Consider the following probability distribution The Normal distribut.pdfArrowdeepak
 
1. Please explain 1. What is cosolidation of a soi 2. What are the .pdf
1. Please explain 1. What is cosolidation of a soi 2. What are the .pdf1. Please explain 1. What is cosolidation of a soi 2. What are the .pdf
1. Please explain 1. What is cosolidation of a soi 2. What are the .pdfArrowdeepak
 
What type of gametes did Sutton predict Mendel (parental, recombin.pdf
What type of gametes did Sutton predict Mendel (parental, recombin.pdfWhat type of gametes did Sutton predict Mendel (parental, recombin.pdf
What type of gametes did Sutton predict Mendel (parental, recombin.pdfArrowdeepak
 
With reference to Barth (2014), discuss how the author assessed the .pdf
With reference to Barth (2014), discuss how the author assessed the .pdfWith reference to Barth (2014), discuss how the author assessed the .pdf
With reference to Barth (2014), discuss how the author assessed the .pdfArrowdeepak
 
1. Peter Grant - the evolutionary biologist who has studied finches .pdf
1. Peter Grant - the evolutionary biologist who has studied finches .pdf1. Peter Grant - the evolutionary biologist who has studied finches .pdf
1. Peter Grant - the evolutionary biologist who has studied finches .pdfArrowdeepak
 
COMMUTER PASSES Five different types of monthly commuter passes are o.pdf
COMMUTER PASSES Five different types of monthly commuter passes are o.pdfCOMMUTER PASSES Five different types of monthly commuter passes are o.pdf
COMMUTER PASSES Five different types of monthly commuter passes are o.pdfArrowdeepak
 
If a researcher rejects a null hypothesis when that hypothesis is ac.pdf
If a researcher rejects a null hypothesis when that hypothesis is ac.pdfIf a researcher rejects a null hypothesis when that hypothesis is ac.pdf
If a researcher rejects a null hypothesis when that hypothesis is ac.pdfArrowdeepak
 
Which of the following values of r allows a perfect prediction of sc.pdf
Which of the following values of r allows a perfect prediction of sc.pdfWhich of the following values of r allows a perfect prediction of sc.pdf
Which of the following values of r allows a perfect prediction of sc.pdfArrowdeepak
 
Which of the following is a way in which meiosis differs from mitosi.pdf
Which of the following is a way in which meiosis differs from mitosi.pdfWhich of the following is a way in which meiosis differs from mitosi.pdf
Which of the following is a way in which meiosis differs from mitosi.pdfArrowdeepak
 
What is the inheritance of the following pedigree X-linked recessiv.pdf
What is the inheritance of the following pedigree  X-linked recessiv.pdfWhat is the inheritance of the following pedigree  X-linked recessiv.pdf
What is the inheritance of the following pedigree X-linked recessiv.pdfArrowdeepak
 
What is the profitability index for an investment with the following.pdf
What is the profitability index for an investment with the following.pdfWhat is the profitability index for an investment with the following.pdf
What is the profitability index for an investment with the following.pdfArrowdeepak
 
What are the characteristics of each microscope 1.compound2.s.pdf
What are the characteristics of each microscope 1.compound2.s.pdfWhat are the characteristics of each microscope 1.compound2.s.pdf
What are the characteristics of each microscope 1.compound2.s.pdfArrowdeepak
 

More from Arrowdeepak (20)

Firefly luciferase is a commonly used reporter gene. The gene origina.pdf
Firefly luciferase is a commonly used reporter gene. The gene origina.pdfFirefly luciferase is a commonly used reporter gene. The gene origina.pdf
Firefly luciferase is a commonly used reporter gene. The gene origina.pdf
 
Find all hazards in this circuit. Redesign the circuit as a three-le.pdf
Find all hazards in this circuit.  Redesign the circuit as a three-le.pdfFind all hazards in this circuit.  Redesign the circuit as a three-le.pdf
Find all hazards in this circuit. Redesign the circuit as a three-le.pdf
 
Fergie has the choice between investing in State of New York bond at.pdf
Fergie has the choice between investing in State of New York bond at.pdfFergie has the choice between investing in State of New York bond at.pdf
Fergie has the choice between investing in State of New York bond at.pdf
 
Explain the “life” of a secreted protein molecule - trace the pathwa.pdf
Explain the “life” of a secreted protein molecule - trace the pathwa.pdfExplain the “life” of a secreted protein molecule - trace the pathwa.pdf
Explain the “life” of a secreted protein molecule - trace the pathwa.pdf
 
7. Using to Table 1 to assist you, explain the rational for the diver.pdf
7. Using to Table 1 to assist you, explain the rational for the diver.pdf7. Using to Table 1 to assist you, explain the rational for the diver.pdf
7. Using to Table 1 to assist you, explain the rational for the diver.pdf
 
A. list two vertebrae that spinal nerve t12 travels between .pdf
A. list two vertebrae that spinal nerve t12 travels between .pdfA. list two vertebrae that spinal nerve t12 travels between .pdf
A. list two vertebrae that spinal nerve t12 travels between .pdf
 
Do people from different cultures experience emotions differently O.pdf
Do people from different cultures experience emotions differently O.pdfDo people from different cultures experience emotions differently O.pdf
Do people from different cultures experience emotions differently O.pdf
 
Describe the basic elements found in robot controllers. (Choose all t.pdf
Describe the basic elements found in robot controllers. (Choose all t.pdfDescribe the basic elements found in robot controllers. (Choose all t.pdf
Describe the basic elements found in robot controllers. (Choose all t.pdf
 
Consider the following probability distribution The Normal distribut.pdf
Consider the following probability distribution  The Normal distribut.pdfConsider the following probability distribution  The Normal distribut.pdf
Consider the following probability distribution The Normal distribut.pdf
 
1. Please explain 1. What is cosolidation of a soi 2. What are the .pdf
1. Please explain 1. What is cosolidation of a soi 2. What are the .pdf1. Please explain 1. What is cosolidation of a soi 2. What are the .pdf
1. Please explain 1. What is cosolidation of a soi 2. What are the .pdf
 
What type of gametes did Sutton predict Mendel (parental, recombin.pdf
What type of gametes did Sutton predict Mendel (parental, recombin.pdfWhat type of gametes did Sutton predict Mendel (parental, recombin.pdf
What type of gametes did Sutton predict Mendel (parental, recombin.pdf
 
With reference to Barth (2014), discuss how the author assessed the .pdf
With reference to Barth (2014), discuss how the author assessed the .pdfWith reference to Barth (2014), discuss how the author assessed the .pdf
With reference to Barth (2014), discuss how the author assessed the .pdf
 
1. Peter Grant - the evolutionary biologist who has studied finches .pdf
1. Peter Grant - the evolutionary biologist who has studied finches .pdf1. Peter Grant - the evolutionary biologist who has studied finches .pdf
1. Peter Grant - the evolutionary biologist who has studied finches .pdf
 
COMMUTER PASSES Five different types of monthly commuter passes are o.pdf
COMMUTER PASSES Five different types of monthly commuter passes are o.pdfCOMMUTER PASSES Five different types of monthly commuter passes are o.pdf
COMMUTER PASSES Five different types of monthly commuter passes are o.pdf
 
If a researcher rejects a null hypothesis when that hypothesis is ac.pdf
If a researcher rejects a null hypothesis when that hypothesis is ac.pdfIf a researcher rejects a null hypothesis when that hypothesis is ac.pdf
If a researcher rejects a null hypothesis when that hypothesis is ac.pdf
 
Which of the following values of r allows a perfect prediction of sc.pdf
Which of the following values of r allows a perfect prediction of sc.pdfWhich of the following values of r allows a perfect prediction of sc.pdf
Which of the following values of r allows a perfect prediction of sc.pdf
 
Which of the following is a way in which meiosis differs from mitosi.pdf
Which of the following is a way in which meiosis differs from mitosi.pdfWhich of the following is a way in which meiosis differs from mitosi.pdf
Which of the following is a way in which meiosis differs from mitosi.pdf
 
What is the inheritance of the following pedigree X-linked recessiv.pdf
What is the inheritance of the following pedigree  X-linked recessiv.pdfWhat is the inheritance of the following pedigree  X-linked recessiv.pdf
What is the inheritance of the following pedigree X-linked recessiv.pdf
 
What is the profitability index for an investment with the following.pdf
What is the profitability index for an investment with the following.pdfWhat is the profitability index for an investment with the following.pdf
What is the profitability index for an investment with the following.pdf
 
What are the characteristics of each microscope 1.compound2.s.pdf
What are the characteristics of each microscope 1.compound2.s.pdfWhat are the characteristics of each microscope 1.compound2.s.pdf
What are the characteristics of each microscope 1.compound2.s.pdf
 

Recently uploaded

Salient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsSalient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsKarakKing
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxAreebaZafar22
 
ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.MaryamAhmad92
 
Google Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptxGoogle Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptxDr. Sarita Anand
 
Towards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptxTowards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptxJisc
 
Fostering Friendships - Enhancing Social Bonds in the Classroom
Fostering Friendships - Enhancing Social Bonds  in the ClassroomFostering Friendships - Enhancing Social Bonds  in the Classroom
Fostering Friendships - Enhancing Social Bonds in the ClassroomPooky Knightsmith
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfciinovamais
 
Vishram Singh - Textbook of Anatomy Upper Limb and Thorax.. Volume 1 (1).pdf
Vishram Singh - Textbook of Anatomy  Upper Limb and Thorax.. Volume 1 (1).pdfVishram Singh - Textbook of Anatomy  Upper Limb and Thorax.. Volume 1 (1).pdf
Vishram Singh - Textbook of Anatomy Upper Limb and Thorax.. Volume 1 (1).pdfssuserdda66b
 
SOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning PresentationSOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning Presentationcamerronhm
 
How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17Celine George
 
Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Jisc
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfAdmir Softic
 
Dyslexia AI Workshop for Slideshare.pptx
Dyslexia AI Workshop for Slideshare.pptxDyslexia AI Workshop for Slideshare.pptx
Dyslexia AI Workshop for Slideshare.pptxcallscotland1987
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxVishalSingh1417
 
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
 
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptxSKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptxAmanpreet Kaur
 
How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17Celine George
 
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptxHMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptxEsquimalt MFRC
 
Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibitjbellavia9
 

Recently uploaded (20)

Salient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsSalient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functions
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptx
 
ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.
 
Google Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptxGoogle Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptx
 
Towards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptxTowards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptx
 
Fostering Friendships - Enhancing Social Bonds in the Classroom
Fostering Friendships - Enhancing Social Bonds  in the ClassroomFostering Friendships - Enhancing Social Bonds  in the Classroom
Fostering Friendships - Enhancing Social Bonds in the Classroom
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
 
Vishram Singh - Textbook of Anatomy Upper Limb and Thorax.. Volume 1 (1).pdf
Vishram Singh - Textbook of Anatomy  Upper Limb and Thorax.. Volume 1 (1).pdfVishram Singh - Textbook of Anatomy  Upper Limb and Thorax.. Volume 1 (1).pdf
Vishram Singh - Textbook of Anatomy Upper Limb and Thorax.. Volume 1 (1).pdf
 
SOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning PresentationSOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning Presentation
 
Spatium Project Simulation student brief
Spatium Project Simulation student briefSpatium Project Simulation student brief
Spatium Project Simulation student brief
 
How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17
 
Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdf
 
Dyslexia AI Workshop for Slideshare.pptx
Dyslexia AI Workshop for Slideshare.pptxDyslexia AI Workshop for Slideshare.pptx
Dyslexia AI Workshop for Slideshare.pptx
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptx
 
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
 
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptxSKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
 
How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17
 
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptxHMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
 
Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibit
 

Write an algorithm that reads a list of integers from the keyboard, .pdf

  • 1. Write an algorithm that reads a list of integers from the keyboard, creates a list of them using linked list implementation, and prints the result Solution /* Algorithm: Implementation of linked list. Create a node type class which will hold an integer and next pointer to point to another node. Create a constructor which will construct an object of type node with the integer type data as the only parameter and initializing next pointer to NULL. Create LinkedList class which will only have head pointer. Create a constructor which will initialize this head pointer to NULL. Create a append method which will recieve an input of type integer from the user and append it to LinkedList using below steps: 1.Create a Node type object. 1.IF head is NULL assign a Node type object created in 1st step. 2.IF head is not NULL then traverse to the end of the linked list till you found a Node which has next pointer set to NULL. 3.Add Node type object created in first step to the next pointer of last node. Create a print method which will traverse the list from the head of the linked list to the last node(Node with next pointer NULL) and while traversing it will keep printing the node data. Get the userinput: Ask user for integer continously till user input -1 and append all the integers to the linked list. */ PROGRAM: #include using namespace std; class Node
  • 2. { public: int data; Node *next; Node(int data) { this->data = data; this->next = NULL; } }; class LinkedList { private: Node *head; public: LinkedList() { head = NULL; } void addToFront(int data) { Node *temp = new Node(data); if(head == NULL) head = temp; else { temp->next = head; head = temp; } } void append(int data) { Node *temp = new Node(data);
  • 3. Node *current = head; if(current == NULL) { head = temp; return; } while(current->next != NULL) { current = current->next; } current->next = temp; } void print() { Node *current = head; if(current == NULL) cout << "No element in list. "; while(current != NULL) { cout << current->data << " "; current = current->next; } cout << endl; } void deleteLinkedList() { Node *prev; Node *current = head;
  • 4. while(current!=NULL) { prev = current; current = current->next; delete prev; } } void deleteLastNode() { Node *current = head; Node *prev = NULL; if(current == NULL) return; while(current->next != NULL) { prev = current; current = current->next; } if(prev == NULL) { delete current; head = NULL; } else { prev->next = NULL; delete current; } } ~LinkedList() {
  • 5. deleteLinkedList(); } }; int main() { LinkedList list; int data; while(1) { cout << "Enter the integer(-1 to Quit) : "; cin >> data; if(data==-1) break; list.append(data); } cout << "Content of LinkedList is : "; list.print(); return 0; } OUTPUT: Enter the integer(-1 to Quit) : 1 Enter the integer(-1 to Quit) : 2 Enter the integer(-1 to Quit) : 3 Enter the integer(-1 to Quit) : 4 Enter the integer(-1 to Quit) : -1 Content of LinkedList is : 1 2 3 4