SlideShare a Scribd company logo
Solve using java and using this Singly linked list class:
public class SLL {
private class SLLNode {
private T info;
private SLLNode next;
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;
}
} The following Questions have to be Solved and Submitted: Part I: Programming ( 50 points)
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).

More Related Content

PDF
Using Java programming language solve the followingSLL CLASS.pdf
PDF
Use the singly linked list class introduced in the lab to implement .pdf
PDF
-JAVA-provide a test class that do the required -you may add met.pdf
PDF
Solve using Java programming language- ----------------------------.pdf
PDF
Submit1) Java Files2) Doc file with the following contents.pdf
PDF
hi i have to write a java program involving link lists. i have a pro.pdf
PDF
Hi,I have added the methods and main class as per your requirement.pdf
PDF
You can list anything, it doesnt matter. I just want to see code f.pdf
Using Java programming language solve the followingSLL CLASS.pdf
Use the singly linked list class introduced in the lab to implement .pdf
-JAVA-provide a test class that do the required -you may add met.pdf
Solve using Java programming language- ----------------------------.pdf
Submit1) Java Files2) Doc file with the following contents.pdf
hi i have to write a java program involving link lists. i have a pro.pdf
Hi,I have added the methods and main class as per your requirement.pdf
You can list anything, it doesnt matter. I just want to see code f.pdf

Similar to Solve using java and using this Singly linked list classpublic cl.pdf (20)

PDF
Fix my codeCode.pdf
PDF
Please help me to make a programming project I have to sue them today- (1).pdf
PDF
Implement the interface you wrote for Lab B (EntryWayListInterface)..pdf
PDF
public class MyLinkedListltE extends ComparableltEgtg.pdf
PDF
PROBLEM STATEMENTIn this assignment, you will complete DoubleEnde.pdf
DOCX
Write java program using linked list to get integer from user and.docx
PDF
please i need help Im writing a program to test the merge sort alg.pdf
PDF
Note             Given Code modified as required and required met.pdf
PDF
Rewrite this code so it can use a generic type instead of integers. .pdf
PDF
The LinkedList1 class implements a Linked list. class.pdf
PDF
Here is the editable codeSolutionimport java.util.NoSuchEleme.pdf
PDF
Exception to indicate that Singly LinkedList is empty. .pdf
PDF
STAGE 2 The Methods 65 points Implement all the methods t.pdf
PDF
Given below is the completed implementation of MyLinkedList class. O.pdf
DOCX
The MyLinkedList class used in Listing 24.6 is a one-way directional .docx
PDF
Write a Java Class to Implement a Generic Linked ListYour list mus.pdf
PDF
Labprogram.javaLinkedList.javaimport java.util.NoSuchElementEx.pdf
PDF
Implement the additional 5 methods as indicated in the LinkedList fi.pdf
PDF
import java.util.Iterator; import java.util.NoSuchElementException; .pdf
PDF
How do I fix it in LinkedList.javaLabProgram.javaLinkedList.jav.pdf
Fix my codeCode.pdf
Please help me to make a programming project I have to sue them today- (1).pdf
Implement the interface you wrote for Lab B (EntryWayListInterface)..pdf
public class MyLinkedListltE extends ComparableltEgtg.pdf
PROBLEM STATEMENTIn this assignment, you will complete DoubleEnde.pdf
Write java program using linked list to get integer from user and.docx
please i need help Im writing a program to test the merge sort alg.pdf
Note             Given Code modified as required and required met.pdf
Rewrite this code so it can use a generic type instead of integers. .pdf
The LinkedList1 class implements a Linked list. class.pdf
Here is the editable codeSolutionimport java.util.NoSuchEleme.pdf
Exception to indicate that Singly LinkedList is empty. .pdf
STAGE 2 The Methods 65 points Implement all the methods t.pdf
Given below is the completed implementation of MyLinkedList class. O.pdf
The MyLinkedList class used in Listing 24.6 is a one-way directional .docx
Write a Java Class to Implement a Generic Linked ListYour list mus.pdf
Labprogram.javaLinkedList.javaimport java.util.NoSuchElementEx.pdf
Implement the additional 5 methods as indicated in the LinkedList fi.pdf
import java.util.Iterator; import java.util.NoSuchElementException; .pdf
How do I fix it in LinkedList.javaLabProgram.javaLinkedList.jav.pdf
Ad

More from aloeplusint (20)

PDF
Starware Software was founded last year to develop software for gami.pdf
PDF
Some obstacles in Project Development. One of the main goals of Proj.pdf
PDF
Sophocles Enterprises had the following pretax income (loss) over it.pdf
PDF
SQL was created at IBM in the 1970s. Why was SQL createdSQL was .pdf
PDF
SQL- Write a select statement that returns the Freight cost from.pdf
PDF
Some of our most basic questions about the history of life concern w.pdf
PDF
Southeastern Oklahoma State Universitys business program has the fa.pdf
PDF
Sorensen Systems Inc. is expected to pay a $2.50 dividend at year en.pdf
PDF
Subject Computer Architecture & Organization Q-4 Assume that .pdf
PDF
Subject Management Information System Please complete the four qu.pdf
PDF
Subject Computer Architecture & Organization i. Show the con.pdf
PDF
Solve the following balance and income sheet for this specialty hosp.pdf
PDF
Su clase se ha ofrecido como voluntaria para trabajar por el Refer�n.pdf
PDF
Su compa��a de TI es responsable de crear programas de virus de soft.pdf
PDF
Study the cladogram above and match the names of the five organisms .pdf
PDF
study of tension, compression, and shear and compare those three dir.pdf
PDF
Start Program like this Chapter 7 Validate Password import.pdf
PDF
Students may research the local Aboriginal andor Torres Strait Isla.pdf
PDF
Stevie es un hombre ocupado. El viaja mucho. Usa las palabras entre .pdf
PDF
Step 1You need to run the JAVA programs in sections 3.3 and 3.5 for.pdf
Starware Software was founded last year to develop software for gami.pdf
Some obstacles in Project Development. One of the main goals of Proj.pdf
Sophocles Enterprises had the following pretax income (loss) over it.pdf
SQL was created at IBM in the 1970s. Why was SQL createdSQL was .pdf
SQL- Write a select statement that returns the Freight cost from.pdf
Some of our most basic questions about the history of life concern w.pdf
Southeastern Oklahoma State Universitys business program has the fa.pdf
Sorensen Systems Inc. is expected to pay a $2.50 dividend at year en.pdf
Subject Computer Architecture & Organization Q-4 Assume that .pdf
Subject Management Information System Please complete the four qu.pdf
Subject Computer Architecture & Organization i. Show the con.pdf
Solve the following balance and income sheet for this specialty hosp.pdf
Su clase se ha ofrecido como voluntaria para trabajar por el Refer�n.pdf
Su compa��a de TI es responsable de crear programas de virus de soft.pdf
Study the cladogram above and match the names of the five organisms .pdf
study of tension, compression, and shear and compare those three dir.pdf
Start Program like this Chapter 7 Validate Password import.pdf
Students may research the local Aboriginal andor Torres Strait Isla.pdf
Stevie es un hombre ocupado. El viaja mucho. Usa las palabras entre .pdf
Step 1You need to run the JAVA programs in sections 3.3 and 3.5 for.pdf
Ad

Recently uploaded (20)

PDF
O7-L3 Supply Chain Operations - ICLT Program
PDF
grade 11-chemistry_fetena_net_5883.pdf teacher guide for all student
PDF
A GUIDE TO GENETICS FOR UNDERGRADUATE MEDICAL STUDENTS
PDF
GENETICS IN BIOLOGY IN SECONDARY LEVEL FORM 3
PDF
102 student loan defaulters named and shamed – Is someone you know on the list?
PPTX
IMMUNITY IMMUNITY refers to protection against infection, and the immune syst...
PDF
OBE - B.A.(HON'S) IN INTERIOR ARCHITECTURE -Ar.MOHIUDDIN.pdf
PPTX
master seminar digital applications in india
PPTX
Institutional Correction lecture only . . .
PDF
Chapter 2 Heredity, Prenatal Development, and Birth.pdf
PPTX
human mycosis Human fungal infections are called human mycosis..pptx
PDF
Black Hat USA 2025 - Micro ICS Summit - ICS/OT Threat Landscape
PPTX
Tissue processing ( HISTOPATHOLOGICAL TECHNIQUE
PDF
Abdominal Access Techniques with Prof. Dr. R K Mishra
PPTX
Pharmacology of Heart Failure /Pharmacotherapy of CHF
PDF
Complications of Minimal Access Surgery at WLH
PDF
Microbial disease of the cardiovascular and lymphatic systems
PPTX
Introduction-to-Literarature-and-Literary-Studies-week-Prelim-coverage.pptx
PDF
STATICS OF THE RIGID BODIES Hibbelers.pdf
PPTX
Lesson notes of climatology university.
O7-L3 Supply Chain Operations - ICLT Program
grade 11-chemistry_fetena_net_5883.pdf teacher guide for all student
A GUIDE TO GENETICS FOR UNDERGRADUATE MEDICAL STUDENTS
GENETICS IN BIOLOGY IN SECONDARY LEVEL FORM 3
102 student loan defaulters named and shamed – Is someone you know on the list?
IMMUNITY IMMUNITY refers to protection against infection, and the immune syst...
OBE - B.A.(HON'S) IN INTERIOR ARCHITECTURE -Ar.MOHIUDDIN.pdf
master seminar digital applications in india
Institutional Correction lecture only . . .
Chapter 2 Heredity, Prenatal Development, and Birth.pdf
human mycosis Human fungal infections are called human mycosis..pptx
Black Hat USA 2025 - Micro ICS Summit - ICS/OT Threat Landscape
Tissue processing ( HISTOPATHOLOGICAL TECHNIQUE
Abdominal Access Techniques with Prof. Dr. R K Mishra
Pharmacology of Heart Failure /Pharmacotherapy of CHF
Complications of Minimal Access Surgery at WLH
Microbial disease of the cardiovascular and lymphatic systems
Introduction-to-Literarature-and-Literary-Studies-week-Prelim-coverage.pptx
STATICS OF THE RIGID BODIES Hibbelers.pdf
Lesson notes of climatology university.

Solve using java and using this Singly linked list classpublic cl.pdf

  • 1. Solve using java and using this Singly linked list class: public class SLL { private class SLLNode { private T info; private SLLNode next; 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);
  • 2. } 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;
  • 3. 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;
  • 4. int count = 0; SLLNode p = head; while(p != null) { count++; p = p.next; } return count; } } The following Questions have to be Solved and Submitted: Part I: Programming ( 50 points) 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).