SlideShare a Scribd company logo
Use the singly linked list class introduced in the lab to implement integers of unlimited size.
Each node of the list should store one digit of the integer. You are to implement the addition,
subtraction and multiplication operations. Please note that any additional data structure to be
used in solving this problem has to be taken from the ones introduced in the ICS 202 lab. In
addition, provide a test class that will do the following: It will keep asking the user to enter two
integers, choose one of the operations (addition, subtraction, multiplication) and then display the
result. The program will stop upon entering the # character (without the double quotes).
this singly linked list class:
public class SLL {
private class SLLNode {
private T info;
private SLLNode next;
int value;
public SLLNode() {
this(null, null);
}
public SLLNode(T el) {
this(el, null);
}
public SLLNode(T el, SLLNode ptr) {
info = el;
next = ptr;
}
}
protected SLLNode head, tail;
public SLL() {
head = tail = null;
}
public boolean isEmpty() {
return head == null;
}
public void addToHead(T el) {
head = new SLLNode(el, head);
if (tail == null)
tail = head;
}
public void addToTail(T el) {
if (!isEmpty()) {
tail.next = new SLLNode(el);
tail = tail.next;
} else
head = tail = new SLLNode(el);
}
public T deleteFromHead() { // delete the head and return its info;
if (isEmpty())
return null;
T el = head.info;
if (head == tail) // if only one node on the list;
head = tail = null;
else
head = head.next;
return el;
}
public T deleteFromTail() { // delete the tail and return its info;
if (isEmpty())
return null;
T el = tail.info;
if (head == tail) // if only one node in the list;
head = tail = null;
else { // if more than one node in the list,
SLLNode tmp; // find the predecessor of tail;
for (tmp = head; tmp.next != tail; tmp = tmp.next)
;
tail = tmp; // the predecessor of tail becomes tail;
tail.next = null;
}
return el;
}
public void delete(T el) { // delete the node with an element el;
if (!isEmpty())
if (head == tail && el.equals(head.info)) // if only one
head = tail = null; // node on the list;
else if (el.equals(head.info)) // if more than one node on the list;
head = head.next; // and el is in the head node;
else { // if more than one node in the list
SLLNode pred, tmp;// and el is in a nonhead node;
for (pred = head, tmp = head.next; tmp != null
&& !tmp.info.equals(el); pred = pred.next, tmp = tmp.next)
;
if (tmp != null) { // if el was found;
pred.next = tmp.next;
if (tmp == tail) // if el is in the last node;
tail = pred;
}
}
}
@Override
public String toString() {
if (head == null)
return "[ ]";
String str = "[ ";
SLLNode tmp = head;
while (tmp != null) {
str += tmp.info + " ";
tmp = tmp.next;
}
return str + "]";
}
public boolean contains(T el) {
if (head == null)
return false;
SLLNode tmp = head;
while (tmp != null) {
if (tmp.info.equals(el))
return true;
tmp = tmp.next;
}
return false;
}
public int size() {
if (head == null)
return 0;
int count = 0;
SLLNode p = head;
while (p != null) {
count++;
p = p.next;
}
return count;
}
}

More Related Content

PDF
Solve using Java programming language- ----------------------------.pdf
PDF
-JAVA-provide a test class that do the required -you may add met.pdf
PDF
Using Java programming language solve the followingSLL CLASS.pdf
PDF
public class SLLT { protected SLLNodeT head, tail; pub.pdf
PDF
Solve using java and using this Singly linked list classpublic cl.pdf
PPTX
Linked list
PDF
Implement the additional 5 methods as indicated in the LinkedList fi.pdf
PDF
Submit1) Java Files2) Doc file with the following contents.pdf
Solve using Java programming language- ----------------------------.pdf
-JAVA-provide a test class that do the required -you may add met.pdf
Using Java programming language solve the followingSLL CLASS.pdf
public class SLLT { protected SLLNodeT head, tail; pub.pdf
Solve using java and using this Singly linked list classpublic cl.pdf
Linked list
Implement the additional 5 methods as indicated in the LinkedList fi.pdf
Submit1) Java Files2) Doc file with the following contents.pdf

Similar to Use the singly linked list class introduced in the lab to implement .pdf (20)

PDF
in C++ , Design a linked list class named IntegerList to hold a seri.pdf
PDF
^^^ Discuss about Header Node And also write a program for unorder.pdf
PDF
Discuss about Header Node And also write a program for unordered si.pdf
PDF
210 Linked-llists of data structure with .pdf
PDF
Data Structures in C++I am really new to C++, so links are really .pdf
PDF
^^^Q2. Discuss about Header Node    And also write a program fo.pdf
PDF
Problem- Describe an algorithm for concatenating two singly linked lis.pdf
PPTX
C Exam Help
PDF
Unit - 2.pdf
PDF
please help me in C++Objective Create a singly linked list of num.pdf
PPT
Data Structure Lecture 6
PDF
Help please!!(Include your modified DList.java source code file in.pdf
PDF
Problem- Describe an algorithm for concatenating two singly linked lis.pdf
PDF
#include sstream #include linkylist.h #include iostream.pdf
PDF
Create your own Linked list from scratch (singly linked list).So.pdf
DOCX
C++ please put everthing after you answer it- thanks Complete the stub.docx
PPTX
Implemention of Linked list concept in Data Structures
PDF
Describe an algorithm for concatenating two singly linked lists L and.pdf
PDF
PROBLEM STATEMENTIn this assignment, you will complete DoubleEnde.pdf
PPT
Unit7 C
in C++ , Design a linked list class named IntegerList to hold a seri.pdf
^^^ Discuss about Header Node And also write a program for unorder.pdf
Discuss about Header Node And also write a program for unordered si.pdf
210 Linked-llists of data structure with .pdf
Data Structures in C++I am really new to C++, so links are really .pdf
^^^Q2. Discuss about Header Node    And also write a program fo.pdf
Problem- Describe an algorithm for concatenating two singly linked lis.pdf
C Exam Help
Unit - 2.pdf
please help me in C++Objective Create a singly linked list of num.pdf
Data Structure Lecture 6
Help please!!(Include your modified DList.java source code file in.pdf
Problem- Describe an algorithm for concatenating two singly linked lis.pdf
#include sstream #include linkylist.h #include iostream.pdf
Create your own Linked list from scratch (singly linked list).So.pdf
C++ please put everthing after you answer it- thanks Complete the stub.docx
Implemention of Linked list concept in Data Structures
Describe an algorithm for concatenating two singly linked lists L and.pdf
PROBLEM STATEMENTIn this assignment, you will complete DoubleEnde.pdf
Unit7 C
Ad

More from sales87 (20)

PDF
Using Martelle�s Chapters 12-14, please describe the impact of WWII .pdf
PDF
Using htmljscss, recreate the sliders. I have attached all images..pdf
PDF
using financial calculatorusing fi.pdf
PDF
Using a Blackjack game that has the classesentities Blackjack, Card.pdf
PDF
Using an Arduino microcontroller to code the following projectDet.pdf
PDF
Use the internet to find an example of a chart or graph.Insert an .pdf
PDF
Use The Wobblies video as a guide httpswww.youtube.comwatchv.pdf
PDF
Use the Plan X and Plan Y tax schemes to complete the following tabl.pdf
PDF
Use the pervious question to answer question 4. Suppose that in car.pdf
PDF
Use the information below to Developdraw a Systemigram for enviro.pdf
PDF
Use the phylogeny below to determine whether each statement is true .pdf
PDF
Use the input function to ask the user for a positive, whole number..pdf
PDF
Use the code below from the previous assignment that we need to exte.pdf
PDF
Use este estudio de caso para responder las siguientes preguntas. .pdf
PDF
Usar su autoridad y poder formal para resolver un conflicto, mientra.pdf
PDF
Usando la teor�a de la expectativa de la motivaci�n como marco para .pdf
PDF
Usando Internet o fuentes de bibliotecas, seleccione cuatro organiza.pdf
PDF
URGENTAssignment 3 - Software DesginPauline is considering how.pdf
PDF
Uscinski and his co-authors describe how belief in political conspir.pdf
PDF
Uno de los beneficios del estado de flujos de efectivo es que ayuda .pdf
Using Martelle�s Chapters 12-14, please describe the impact of WWII .pdf
Using htmljscss, recreate the sliders. I have attached all images..pdf
using financial calculatorusing fi.pdf
Using a Blackjack game that has the classesentities Blackjack, Card.pdf
Using an Arduino microcontroller to code the following projectDet.pdf
Use the internet to find an example of a chart or graph.Insert an .pdf
Use The Wobblies video as a guide httpswww.youtube.comwatchv.pdf
Use the Plan X and Plan Y tax schemes to complete the following tabl.pdf
Use the pervious question to answer question 4. Suppose that in car.pdf
Use the information below to Developdraw a Systemigram for enviro.pdf
Use the phylogeny below to determine whether each statement is true .pdf
Use the input function to ask the user for a positive, whole number..pdf
Use the code below from the previous assignment that we need to exte.pdf
Use este estudio de caso para responder las siguientes preguntas. .pdf
Usar su autoridad y poder formal para resolver un conflicto, mientra.pdf
Usando la teor�a de la expectativa de la motivaci�n como marco para .pdf
Usando Internet o fuentes de bibliotecas, seleccione cuatro organiza.pdf
URGENTAssignment 3 - Software DesginPauline is considering how.pdf
Uscinski and his co-authors describe how belief in political conspir.pdf
Uno de los beneficios del estado de flujos de efectivo es que ayuda .pdf
Ad

Recently uploaded (20)

PDF
Saundersa Comprehensive Review for the NCLEX-RN Examination.pdf
PPTX
Pharma ospi slides which help in ospi learning
PPTX
Institutional Correction lecture only . . .
PPTX
IMMUNITY IMMUNITY refers to protection against infection, and the immune syst...
PPTX
Final Presentation General Medicine 03-08-2024.pptx
PDF
Complications of Minimal Access Surgery at WLH
PDF
O7-L3 Supply Chain Operations - ICLT Program
PDF
RMMM.pdf make it easy to upload and study
PPTX
Pharmacology of Heart Failure /Pharmacotherapy of CHF
PDF
Supply Chain Operations Speaking Notes -ICLT Program
PDF
Anesthesia in Laparoscopic Surgery in India
PPTX
Lesson notes of climatology university.
PDF
Chapter 2 Heredity, Prenatal Development, and Birth.pdf
PPTX
Final Presentation General Medicine 03-08-2024.pptx
PPTX
Tissue processing ( HISTOPATHOLOGICAL TECHNIQUE
PDF
grade 11-chemistry_fetena_net_5883.pdf teacher guide for all student
PPTX
Microbial diseases, their pathogenesis and prophylaxis
PPTX
human mycosis Human fungal infections are called human mycosis..pptx
PDF
Computing-Curriculum for Schools in Ghana
PDF
2.FourierTransform-ShortQuestionswithAnswers.pdf
Saundersa Comprehensive Review for the NCLEX-RN Examination.pdf
Pharma ospi slides which help in ospi learning
Institutional Correction lecture only . . .
IMMUNITY IMMUNITY refers to protection against infection, and the immune syst...
Final Presentation General Medicine 03-08-2024.pptx
Complications of Minimal Access Surgery at WLH
O7-L3 Supply Chain Operations - ICLT Program
RMMM.pdf make it easy to upload and study
Pharmacology of Heart Failure /Pharmacotherapy of CHF
Supply Chain Operations Speaking Notes -ICLT Program
Anesthesia in Laparoscopic Surgery in India
Lesson notes of climatology university.
Chapter 2 Heredity, Prenatal Development, and Birth.pdf
Final Presentation General Medicine 03-08-2024.pptx
Tissue processing ( HISTOPATHOLOGICAL TECHNIQUE
grade 11-chemistry_fetena_net_5883.pdf teacher guide for all student
Microbial diseases, their pathogenesis and prophylaxis
human mycosis Human fungal infections are called human mycosis..pptx
Computing-Curriculum for Schools in Ghana
2.FourierTransform-ShortQuestionswithAnswers.pdf

Use the singly linked list class introduced in the lab to implement .pdf

  • 1. Use the singly linked list class introduced in the lab to implement integers of unlimited size. Each node of the list should store one digit of the integer. You are to implement the addition, subtraction and multiplication operations. Please note that any additional data structure to be used in solving this problem has to be taken from the ones introduced in the ICS 202 lab. In addition, provide a test class that will do the following: It will keep asking the user to enter two integers, choose one of the operations (addition, subtraction, multiplication) and then display the result. The program will stop upon entering the # character (without the double quotes). this singly linked list class: public class SLL { private class SLLNode { private T info; private SLLNode next; int value; public SLLNode() { this(null, null); } public SLLNode(T el) { this(el, null); } public SLLNode(T el, SLLNode ptr) { info = el; next = ptr; } } protected SLLNode head, tail; public SLL() { head = tail = null;
  • 2. } public boolean isEmpty() { return head == null; } public void addToHead(T el) { head = new SLLNode(el, head); if (tail == null) tail = head; } public void addToTail(T el) { if (!isEmpty()) { tail.next = new SLLNode(el); tail = tail.next; } else head = tail = new SLLNode(el); } public T deleteFromHead() { // delete the head and return its info; if (isEmpty()) return null; T el = head.info; if (head == tail) // if only one node on the list; head = tail = null; else head = head.next; return el; } public T deleteFromTail() { // delete the tail and return its info; if (isEmpty()) return null; T el = tail.info; if (head == tail) // if only one node in the list;
  • 3. head = tail = null; else { // if more than one node in the list, SLLNode tmp; // find the predecessor of tail; for (tmp = head; tmp.next != tail; tmp = tmp.next) ; tail = tmp; // the predecessor of tail becomes tail; tail.next = null; } return el; } public void delete(T el) { // delete the node with an element el; if (!isEmpty()) if (head == tail && el.equals(head.info)) // if only one head = tail = null; // node on the list; else if (el.equals(head.info)) // if more than one node on the list; head = head.next; // and el is in the head node; else { // if more than one node in the list SLLNode pred, tmp;// and el is in a nonhead node; for (pred = head, tmp = head.next; tmp != null && !tmp.info.equals(el); pred = pred.next, tmp = tmp.next) ; if (tmp != null) { // if el was found; pred.next = tmp.next; if (tmp == tail) // if el is in the last node; tail = pred; } } } @Override public String toString() { if (head == null) return "[ ]"; String str = "[ "; SLLNode tmp = head;
  • 4. while (tmp != null) { str += tmp.info + " "; tmp = tmp.next; } return str + "]"; } public boolean contains(T el) { if (head == null) return false; SLLNode tmp = head; while (tmp != null) { if (tmp.info.equals(el)) return true; tmp = tmp.next; } return false; } public int size() { if (head == null) return 0; int count = 0; SLLNode p = head; while (p != null) { count++; p = p.next; } return count; } }