SlideShare a Scribd company logo
1 of 2
Download to read offline
public class SLL { protected SLLNode head, tail; public SLL() { head = tail = null;
} public void addToTail(T e){ SLLNode newNode = new SLLNode(e); if(head ==
null) head = tail = newNode; else{ tail.next = newNode; tail =
tail.next; } } public void addToHead(T e) { SLLNode newNode = new
SLLNode(e, head); if(head == null) tail = newNode; head = newNode; }
public String toString(){ if (head == null) return "[]"; String out = "[";
SLLNode p = head; while (p.next != null){ out += p.info + " "; p = p.next;
} out += p.info + "]"; return out; } }
public class SLLNode { protected T info; protected SLLNode next; public SLLNode() {
this(null, null); } public SLLNode(T e) { this(e, null); } public SLLNode(T
e, SLLNode ptr) { info = e; next = ptr; } }
public class SortedSLL> extends SLL{ public void insert(T e){ } public void
merge(SortedSLL list){ } }
public class SortedSLL T extends Comparable T extends SLLT{ public void insert (T e) { }
public void merge(SortedSLL T list) { } public class SortedSLL T extends Comparable T
extends SLLT{ public void insert ( T e) { } public void merge(SortedSLL T list) { } }
ublic class SLLT{ protected SLLNodeT head, tail; public SLL() { head = tail = null; } public
void addToTail( T e) { SLLNode newNode = new SLLNodeT(e); if ( head == null) head = tail
= newNode; else{ tail. next = newNode; tail = tail. next; } } public void addToHead( T e) {
SLLNode T newNode = new SLLNodeT(e, head ); if (head == null) tail = newNode; head =
newNode; } public string tostring(){ if (head == null) return "[]"; String out = "["; SLLNode
Tp= head; while (p.next != null) { out +=p.info +" "; p=p next; } out += p.info + "]"; return out;
}
ublic class SLLNode T{ protected T info; protected SLLNode T next; public SLLNode() {
this(null, null); } public SLLNode( T e) { this (e, null); } public SLLNode( T e, SLLNode T
ptr ){ info =e; next =ptr; }
Write a subclass of SLL named SortedSLL that represents a sorted SinglyLinkedList (sorted in
nondecending order). The class should contain the following methods: 1- [40 Points] void insert
( T e) that inserts an SLLNode in its correct position so that the resulting list remains sorted.
Make sure to consider special cases such as: - The list is empty. - The list has one element. - The
inserted element is smaller than the head, or larger than the tail.. 2- [60 Points] void
merge(SortedSLL T list) that merges the calling list with the argument list. Note that this can be
done by calling the insert method for each element in list, but this is highly ineffiecient, answer
the following question: Q2.1: What is the complexity of this approach? Explain. [10 Points]
Instead, you should come up with a solution that traverse both lists just one time. Furthermore,
the argument list should be empty after the merge is completed. Q2.2: What is the complexity of
this approach? Explain. [10 Points] Hint: Make sure the class SortedSLL accepts types T that is
comparable. You can do this by writing the class header as follows: public class SortedSLL T
extends Comparable T extends SLLT Notes: - Do not use additional data structures: e.g. arrays,
arraylists, strings, etc. - For the insert method, your solution should be adding a node to a list,
without re-creating the list, and without using a helper data structure or a sorting algorithm. - Use
the attached SLL and SLLNode classes. DO NOT modify these two classes. - Write your code in
the attached SortedSLL class, you can add helper methods, but DO NOT change the header of
insert and merge methods.

More Related Content

Similar to public class SLLT { protected SLLNodeT head, tail; pub.pdf

You can list anything, it doesnt matter. I just want to see code f.pdf
You can list anything, it doesnt matter. I just want to see code f.pdfYou can list anything, it doesnt matter. I just want to see code f.pdf
You can list anything, it doesnt matter. I just want to see code f.pdf
fashionbigchennai
 
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
aminbijal86
 
Solutionclass IntNode { int data; public IntNode next,head;.pdf
Solutionclass IntNode { int data; public IntNode next,head;.pdfSolutionclass IntNode { int data; public IntNode next,head;.pdf
Solutionclass IntNode { int data; public IntNode next,head;.pdf
rakeshankur
 
Create your own Linked list from scratch (singly linked list).So.pdf
Create your own Linked list from scratch (singly linked list).So.pdfCreate your own Linked list from scratch (singly linked list).So.pdf
Create your own Linked list from scratch (singly linked list).So.pdf
arumugambags
 
#include sstream #include linkylist.h #include iostream.pdf
#include sstream #include linkylist.h #include iostream.pdf#include sstream #include linkylist.h #include iostream.pdf
#include sstream #include linkylist.h #include iostream.pdf
aravlitraders2012
 
Add delete at a position to the code and display it to the code- class.pdf
Add delete at a position to the code and display it to the code- class.pdfAdd delete at a position to the code and display it to the code- class.pdf
Add delete at a position to the code and display it to the code- class.pdf
yrajjoshi
 
So I have this code(StackInAllSocks) and I implemented the method but.pdf
So I have this code(StackInAllSocks) and I implemented the method but.pdfSo I have this code(StackInAllSocks) and I implemented the method but.pdf
So I have this code(StackInAllSocks) and I implemented the method but.pdf
aksahnan
 
I need to fill-in TODOs in .cpp file and in .h file Could some.pdf
I need to fill-in TODOs in .cpp file and in .h file Could some.pdfI need to fill-in TODOs in .cpp file and in .h file Could some.pdf
I need to fill-in TODOs in .cpp file and in .h file Could some.pdf
forladies
 
Rewrite this code so it can use a generic type instead of integers. .pdf
Rewrite this code so it can use a generic type instead of integers. .pdfRewrite this code so it can use a generic type instead of integers. .pdf
Rewrite this code so it can use a generic type instead of integers. .pdf
alphaagenciesindia
 
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
rohit219406
 
Please finish the int LLInsert function.typedef struct STUDENT {.pdf
Please finish the int LLInsert function.typedef struct STUDENT {.pdfPlease finish the int LLInsert function.typedef struct STUDENT {.pdf
Please finish the int LLInsert function.typedef struct STUDENT {.pdf
fortmdu
 

Similar to public class SLLT { protected SLLNodeT head, tail; pub.pdf (20)

Linked list
Linked list Linked list
Linked list
 
fix the error - class Node{ int data- Node next-.pdf
fix the error -   class Node{           int data-           Node next-.pdffix the error -   class Node{           int data-           Node next-.pdf
fix the error - class Node{ int data- Node next-.pdf
 
dynamicList.ppt
dynamicList.pptdynamicList.ppt
dynamicList.ppt
 
Data structure
Data  structureData  structure
Data structure
 
You can list anything, it doesnt matter. I just want to see code f.pdf
You can list anything, it doesnt matter. I just want to see code f.pdfYou can list anything, it doesnt matter. I just want to see code f.pdf
You can list anything, it doesnt matter. I just want to see code f.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
 
Solutionclass IntNode { int data; public IntNode next,head;.pdf
Solutionclass IntNode { int data; public IntNode next,head;.pdfSolutionclass IntNode { int data; public IntNode next,head;.pdf
Solutionclass IntNode { int data; public IntNode next,head;.pdf
 
Create your own Linked list from scratch (singly linked list).So.pdf
Create your own Linked list from scratch (singly linked list).So.pdfCreate your own Linked list from scratch (singly linked list).So.pdf
Create your own Linked list from scratch (singly linked list).So.pdf
 
#include sstream #include linkylist.h #include iostream.pdf
#include sstream #include linkylist.h #include iostream.pdf#include sstream #include linkylist.h #include iostream.pdf
#include sstream #include linkylist.h #include iostream.pdf
 
CSE240 Doubly Linked Lists
CSE240 Doubly Linked ListsCSE240 Doubly Linked Lists
CSE240 Doubly Linked Lists
 
137 Lab-2.2.pdf
137 Lab-2.2.pdf137 Lab-2.2.pdf
137 Lab-2.2.pdf
 
Add delete at a position to the code and display it to the code- class.pdf
Add delete at a position to the code and display it to the code- class.pdfAdd delete at a position to the code and display it to the code- class.pdf
Add delete at a position to the code and display it to the code- class.pdf
 
So I have this code(StackInAllSocks) and I implemented the method but.pdf
So I have this code(StackInAllSocks) and I implemented the method but.pdfSo I have this code(StackInAllSocks) and I implemented the method but.pdf
So I have this code(StackInAllSocks) and I implemented the method but.pdf
 
I need to fill-in TODOs in .cpp file and in .h file Could some.pdf
I need to fill-in TODOs in .cpp file and in .h file Could some.pdfI need to fill-in TODOs in .cpp file and in .h file Could some.pdf
I need to fill-in TODOs in .cpp file and in .h file Could some.pdf
 
C Programming Homework Help
C Programming Homework HelpC Programming Homework Help
C Programming Homework Help
 
Linked lists
Linked listsLinked lists
Linked lists
 
Rewrite this code so it can use a generic type instead of integers. .pdf
Rewrite this code so it can use a generic type instead of integers. .pdfRewrite this code so it can use a generic type instead of integers. .pdf
Rewrite this code so it can use a generic type instead of integers. .pdf
 
Linked Stack program.docx
Linked Stack program.docxLinked Stack program.docx
Linked Stack program.docx
 
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
 
Please finish the int LLInsert function.typedef struct STUDENT {.pdf
Please finish the int LLInsert function.typedef struct STUDENT {.pdfPlease finish the int LLInsert function.typedef struct STUDENT {.pdf
Please finish the int LLInsert function.typedef struct STUDENT {.pdf
 

More from clarityvision

Q1How would this be explained in the witness box, how would this lo.pdf
Q1How would this be explained in the witness box, how would this lo.pdfQ1How would this be explained in the witness box, how would this lo.pdf
Q1How would this be explained in the witness box, how would this lo.pdf
clarityvision
 
Shell to be modified#include stdlib.h #include unistd.h .pdf
Shell to be modified#include stdlib.h #include unistd.h .pdfShell to be modified#include stdlib.h #include unistd.h .pdf
Shell to be modified#include stdlib.h #include unistd.h .pdf
clarityvision
 
Project Advanced Inventory Management System Upgrade for ABCBio.pdf
Project Advanced Inventory Management System Upgrade for ABCBio.pdfProject Advanced Inventory Management System Upgrade for ABCBio.pdf
Project Advanced Inventory Management System Upgrade for ABCBio.pdf
clarityvision
 
Procuring textiles made from recycled fibresBackgroundThe Mini.pdf
Procuring textiles made from recycled fibresBackgroundThe Mini.pdfProcuring textiles made from recycled fibresBackgroundThe Mini.pdf
Procuring textiles made from recycled fibresBackgroundThe Mini.pdf
clarityvision
 
Read the following excerpt and answer the questions that followPle.pdf
Read the following excerpt and answer the questions that followPle.pdfRead the following excerpt and answer the questions that followPle.pdf
Read the following excerpt and answer the questions that followPle.pdf
clarityvision
 
Question 4 Read the case study about Ms Zandi and then answer the fo.pdf
Question 4 Read the case study about Ms Zandi and then answer the fo.pdfQuestion 4 Read the case study about Ms Zandi and then answer the fo.pdf
Question 4 Read the case study about Ms Zandi and then answer the fo.pdf
clarityvision
 

More from clarityvision (10)

Q1How would this be explained in the witness box, how would this lo.pdf
Q1How would this be explained in the witness box, how would this lo.pdfQ1How would this be explained in the witness box, how would this lo.pdf
Q1How would this be explained in the witness box, how would this lo.pdf
 
Professor Lessiarty directs an underground network of n criminal maste.pdf
Professor Lessiarty directs an underground network of n criminal maste.pdfProfessor Lessiarty directs an underground network of n criminal maste.pdf
Professor Lessiarty directs an underground network of n criminal maste.pdf
 
Shell to be modified#include stdlib.h #include unistd.h .pdf
Shell to be modified#include stdlib.h #include unistd.h .pdfShell to be modified#include stdlib.h #include unistd.h .pdf
Shell to be modified#include stdlib.h #include unistd.h .pdf
 
Project Advanced Inventory Management System Upgrade for ABCBio.pdf
Project Advanced Inventory Management System Upgrade for ABCBio.pdfProject Advanced Inventory Management System Upgrade for ABCBio.pdf
Project Advanced Inventory Management System Upgrade for ABCBio.pdf
 
Scenario 3 Capacity and Legality Micah was a talented tennis player a.pdf
Scenario 3 Capacity and Legality  Micah was a talented tennis player a.pdfScenario 3 Capacity and Legality  Micah was a talented tennis player a.pdf
Scenario 3 Capacity and Legality Micah was a talented tennis player a.pdf
 
Scenario 2 Types of Contracts Dr. Brown was an adjunct instructor at.pdf
Scenario 2 Types of Contracts  Dr. Brown was an adjunct instructor at.pdfScenario 2 Types of Contracts  Dr. Brown was an adjunct instructor at.pdf
Scenario 2 Types of Contracts Dr. Brown was an adjunct instructor at.pdf
 
PROJECT 2Construction of a Medical ClinicMany people were severe.pdf
PROJECT 2Construction of a Medical ClinicMany people were severe.pdfPROJECT 2Construction of a Medical ClinicMany people were severe.pdf
PROJECT 2Construction of a Medical ClinicMany people were severe.pdf
 
Procuring textiles made from recycled fibresBackgroundThe Mini.pdf
Procuring textiles made from recycled fibresBackgroundThe Mini.pdfProcuring textiles made from recycled fibresBackgroundThe Mini.pdf
Procuring textiles made from recycled fibresBackgroundThe Mini.pdf
 
Read the following excerpt and answer the questions that followPle.pdf
Read the following excerpt and answer the questions that followPle.pdfRead the following excerpt and answer the questions that followPle.pdf
Read the following excerpt and answer the questions that followPle.pdf
 
Question 4 Read the case study about Ms Zandi and then answer the fo.pdf
Question 4 Read the case study about Ms Zandi and then answer the fo.pdfQuestion 4 Read the case study about Ms Zandi and then answer the fo.pdf
Question 4 Read the case study about Ms Zandi and then answer the fo.pdf
 

Recently uploaded

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
ssuserdda66b
 

Recently uploaded (20)

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.
 
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfUGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
 
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
 
Unit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptxUnit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptx
 
Single or Multiple melodic lines structure
Single or Multiple melodic lines structureSingle or Multiple melodic lines structure
Single or Multiple melodic lines structure
 
FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024
 
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
 
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
 
On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan Fellows
 
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
 
Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptx
 
Graduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - EnglishGraduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - English
 
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
 
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
 
Spatium Project Simulation student brief
Spatium Project Simulation student briefSpatium Project Simulation student brief
Spatium Project Simulation student brief
 
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
 
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
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdf
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.
 

public class SLLT { protected SLLNodeT head, tail; pub.pdf

  • 1. public class SLL { protected SLLNode head, tail; public SLL() { head = tail = null; } public void addToTail(T e){ SLLNode newNode = new SLLNode(e); if(head == null) head = tail = newNode; else{ tail.next = newNode; tail = tail.next; } } public void addToHead(T e) { SLLNode newNode = new SLLNode(e, head); if(head == null) tail = newNode; head = newNode; } public String toString(){ if (head == null) return "[]"; String out = "["; SLLNode p = head; while (p.next != null){ out += p.info + " "; p = p.next; } out += p.info + "]"; return out; } } public class SLLNode { protected T info; protected SLLNode next; public SLLNode() { this(null, null); } public SLLNode(T e) { this(e, null); } public SLLNode(T e, SLLNode ptr) { info = e; next = ptr; } } public class SortedSLL> extends SLL{ public void insert(T e){ } public void merge(SortedSLL list){ } } public class SortedSLL T extends Comparable T extends SLLT{ public void insert (T e) { } public void merge(SortedSLL T list) { } public class SortedSLL T extends Comparable T extends SLLT{ public void insert ( T e) { } public void merge(SortedSLL T list) { } } ublic class SLLT{ protected SLLNodeT head, tail; public SLL() { head = tail = null; } public void addToTail( T e) { SLLNode newNode = new SLLNodeT(e); if ( head == null) head = tail = newNode; else{ tail. next = newNode; tail = tail. next; } } public void addToHead( T e) { SLLNode T newNode = new SLLNodeT(e, head ); if (head == null) tail = newNode; head = newNode; } public string tostring(){ if (head == null) return "[]"; String out = "["; SLLNode Tp= head; while (p.next != null) { out +=p.info +" "; p=p next; } out += p.info + "]"; return out; } ublic class SLLNode T{ protected T info; protected SLLNode T next; public SLLNode() { this(null, null); } public SLLNode( T e) { this (e, null); } public SLLNode( T e, SLLNode T
  • 2. ptr ){ info =e; next =ptr; } Write a subclass of SLL named SortedSLL that represents a sorted SinglyLinkedList (sorted in nondecending order). The class should contain the following methods: 1- [40 Points] void insert ( T e) that inserts an SLLNode in its correct position so that the resulting list remains sorted. Make sure to consider special cases such as: - The list is empty. - The list has one element. - The inserted element is smaller than the head, or larger than the tail.. 2- [60 Points] void merge(SortedSLL T list) that merges the calling list with the argument list. Note that this can be done by calling the insert method for each element in list, but this is highly ineffiecient, answer the following question: Q2.1: What is the complexity of this approach? Explain. [10 Points] Instead, you should come up with a solution that traverse both lists just one time. Furthermore, the argument list should be empty after the merge is completed. Q2.2: What is the complexity of this approach? Explain. [10 Points] Hint: Make sure the class SortedSLL accepts types T that is comparable. You can do this by writing the class header as follows: public class SortedSLL T extends Comparable T extends SLLT Notes: - Do not use additional data structures: e.g. arrays, arraylists, strings, etc. - For the insert method, your solution should be adding a node to a list, without re-creating the list, and without using a helper data structure or a sorting algorithm. - Use the attached SLL and SLLNode classes. DO NOT modify these two classes. - Write your code in the attached SortedSLL class, you can add helper methods, but DO NOT change the header of insert and merge methods.