SlideShare a Scribd company logo
1 of 7
Download to read offline
Submit:
1) Java Files
2) Doc file with the following contents:
//************************** SLL.java *********************************
// a generic 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;
}
}
public class SLL_Driver {
public static void main(String[] args) {
SLL myList = new SLL();
String[] cityNames = {"Jubail", "Riyadh", "Abha", "Dammam", "Taif"};
for(int i = 0; i < cityNames.length; i++)
myList.addToHead(cityNames[i]);
System.out.println("The list is: " + myList);
System.out.println("It is " + myList.contains("Dammam") + " that the list contains
Dammam.");
System.out.println("It is " + myList.contains("Jeddah") + " that the list contains Jeddah.");
}
}
// Java program to implement a queue using an array
public class QueueAsArray {
private int front, rear, capacity;
private T[] queue;
public QueueAsArray(int capacity) {
front = rear = -1;
this.capacity = capacity;
queue = (T[]) new Object[capacity];
}
public boolean isEmpty(){
return front == -1;
}
public boolean isFull(){
return rear == capacity - 1;
}
// function to insert an element at the rear of the queue
public void enqueue(T data) {
if (isFull())
throw new UnsupportedOperationException("Queue is full!");
if(isEmpty())
front++;
rear++;
queue[rear] = data;
}
public T dequeue() {
if (isEmpty())
throw new UnsupportedOperationException("Queue is empty!");
T temp = queue[front];
if (rear == 0) {
rear = front = -1;
}
else{
for(int i = 0; i <= rear - 1; i++) {
queue[i] = queue[i + 1];
}
rear--;
}
return temp;
}
public boolean search(T e){
if (isEmpty())
throw new UnsupportedOperationException("Queue is empty!");
for(int i = 0; i <= rear; i++)
if(e.equals(queue[i]))
return true;
return false;
}
public String toString() {
if (isEmpty())
throw new UnsupportedOperationException("Queue is empty!");
String str = "";
for (int i = 0; i <= rear; i++) {
str = str + queue[i] + " ";
}
return str;
}
public T peek() {
if (isEmpty())
throw new UnsupportedOperationException("Queue is empty!");
return queue[front];
}
} King Fahd University of Petroleum & Minerals College of Computer Science and
Engineering Information and Computer Science Department ICS 202 - Data Structures
Recursion Objectives The objective of this lab is to design and implement recursive programs.
Outcomes After completing this Lab, students are expected to: Design recursive solutions. -
Implement recursive methods. Lab Tasks 1. (a) Comment the iterative public boolean
contains(Element e) method of the given SLL class then implement it as a recursive method. Use
appropriate helper method in your solution. (c) Use the given test program to test your recursive
methods. Sample program run: The list is: [ Taif Dammam Abha Riyadh Jubail ] It is true that
the list contains Dammam. It is false that the list contains Jeddah. 2. (a) Comment the iterative
public T dequeue () method of the given class QueueAsArray then implement it as a recursive
method. Use an appropriate helper method in your solution. (b) Write a test program to test the
recursive dequeue method. Sample program run: The queue is: 6020403070 First dequeued
element is: 60 Second dequeued element is: 20 After two node deletion the queue is: 403070
Element at queue front is: 4

More Related Content

Similar to Submit1) Java Files2) Doc file with the following contents.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.pdfforladies
 
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
 
#includeiostream struct node {    char value;    struct no.pdf
#includeiostream struct node {    char value;    struct no.pdf#includeiostream struct node {    char value;    struct no.pdf
#includeiostream struct node {    char value;    struct no.pdfankitmobileshop235
 
#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.pdfaravlitraders2012
 
import java-util--- public class MyLinkedList{ public static void.pdf
import java-util---  public class MyLinkedList{    public static void.pdfimport java-util---  public class MyLinkedList{    public static void.pdf
import java-util--- public class MyLinkedList{ public static void.pdfasarudheen07
 
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. .pdfalphaagenciesindia
 
#include iostream #include cstring #include vector #i.pdf
 #include iostream #include cstring #include vector #i.pdf #include iostream #include cstring #include vector #i.pdf
#include iostream #include cstring #include vector #i.pdfanandatalapatra
 
mainpublic class AssignmentThree {    public static void ma.pdf
mainpublic class AssignmentThree {    public static void ma.pdfmainpublic class AssignmentThree {    public static void ma.pdf
mainpublic class AssignmentThree {    public static void ma.pdffathimafancyjeweller
 
Table.java Huffman code frequency tableimport java.io.;im.docx
 Table.java Huffman code frequency tableimport java.io.;im.docx Table.java Huffman code frequency tableimport java.io.;im.docx
Table.java Huffman code frequency tableimport java.io.;im.docxMARRY7
 
JAVA OOP project; desperately need help asap im begging.Been stuck.pdf
JAVA OOP project; desperately need help asap im begging.Been stuck.pdfJAVA OOP project; desperately need help asap im begging.Been stuck.pdf
JAVA OOP project; desperately need help asap im begging.Been stuck.pdffantasiatheoutofthef
 
Link list part 2
Link list part 2Link list part 2
Link list part 2Anaya Zafar
 
Scala vs Java 8 in a Java 8 World
Scala vs Java 8 in a Java 8 WorldScala vs Java 8 in a Java 8 World
Scala vs Java 8 in a Java 8 WorldBTI360
 
import java-util-Iterator- import java-util-NoSuchElementException- im.pdf
import java-util-Iterator- import java-util-NoSuchElementException- im.pdfimport java-util-Iterator- import java-util-NoSuchElementException- im.pdf
import java-util-Iterator- import java-util-NoSuchElementException- im.pdfStewart29UReesa
 
Singly linked list.pptx
Singly linked list.pptxSingly linked list.pptx
Singly linked list.pptxSanthiya S
 

Similar to Submit1) Java Files2) Doc file with the following contents.pdf (20)

DS Code (CWH).docx
DS Code (CWH).docxDS Code (CWH).docx
DS Code (CWH).docx
 
137 Lab-2.2.pdf
137 Lab-2.2.pdf137 Lab-2.2.pdf
137 Lab-2.2.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
 
Linked lists
Linked listsLinked lists
Linked lists
 
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
 
#includeiostream struct node {    char value;    struct no.pdf
#includeiostream struct node {    char value;    struct no.pdf#includeiostream struct node {    char value;    struct no.pdf
#includeiostream struct node {    char value;    struct no.pdf
 
Lab-2.2 717822E504.pdf
Lab-2.2 717822E504.pdfLab-2.2 717822E504.pdf
Lab-2.2 717822E504.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
 
import java-util--- public class MyLinkedList{ public static void.pdf
import java-util---  public class MyLinkedList{    public static void.pdfimport java-util---  public class MyLinkedList{    public static void.pdf
import java-util--- public class MyLinkedList{ public static void.pdf
 
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
 
#include iostream #include cstring #include vector #i.pdf
 #include iostream #include cstring #include vector #i.pdf #include iostream #include cstring #include vector #i.pdf
#include iostream #include cstring #include vector #i.pdf
 
mainpublic class AssignmentThree {    public static void ma.pdf
mainpublic class AssignmentThree {    public static void ma.pdfmainpublic class AssignmentThree {    public static void ma.pdf
mainpublic class AssignmentThree {    public static void ma.pdf
 
Table.java Huffman code frequency tableimport java.io.;im.docx
 Table.java Huffman code frequency tableimport java.io.;im.docx Table.java Huffman code frequency tableimport java.io.;im.docx
Table.java Huffman code frequency tableimport java.io.;im.docx
 
Linked lists
Linked listsLinked lists
Linked lists
 
JAVA OOP project; desperately need help asap im begging.Been stuck.pdf
JAVA OOP project; desperately need help asap im begging.Been stuck.pdfJAVA OOP project; desperately need help asap im begging.Been stuck.pdf
JAVA OOP project; desperately need help asap im begging.Been stuck.pdf
 
Link list part 2
Link list part 2Link list part 2
Link list part 2
 
Scala vs Java 8 in a Java 8 World
Scala vs Java 8 in a Java 8 WorldScala vs Java 8 in a Java 8 World
Scala vs Java 8 in a Java 8 World
 
import java-util-Iterator- import java-util-NoSuchElementException- im.pdf
import java-util-Iterator- import java-util-NoSuchElementException- im.pdfimport java-util-Iterator- import java-util-NoSuchElementException- im.pdf
import java-util-Iterator- import java-util-NoSuchElementException- im.pdf
 
Singly linked list.pptx
Singly linked list.pptxSingly linked list.pptx
Singly linked list.pptx
 
C Programming Homework Help
C Programming Homework HelpC Programming Homework Help
C Programming Homework Help
 

More from akaluza07

Suppose a division of Washington Instruments Incorporated that sells.pdf
Suppose a division of Washington Instruments Incorporated that sells.pdfSuppose a division of Washington Instruments Incorporated that sells.pdf
Suppose a division of Washington Instruments Incorporated that sells.pdfakaluza07
 
Use the ER Diagram that you created in your Homework Assignment ER .pdf
Use the ER Diagram that you created in your Homework Assignment ER .pdfUse the ER Diagram that you created in your Homework Assignment ER .pdf
Use the ER Diagram that you created in your Homework Assignment ER .pdfakaluza07
 
Use the ER Diagram that you created in your Homework Assignment ER.pdf
Use the ER Diagram that you created in your Homework Assignment  ER.pdfUse the ER Diagram that you created in your Homework Assignment  ER.pdf
Use the ER Diagram that you created in your Homework Assignment ER.pdfakaluza07
 
This is to test a balanced tree. I need help testing an unbalanced t.pdf
This is to test a balanced tree. I need help testing an unbalanced t.pdfThis is to test a balanced tree. I need help testing an unbalanced t.pdf
This is to test a balanced tree. I need help testing an unbalanced t.pdfakaluza07
 
This includes the following � Setup MongoDB in the cloud � Gen.pdf
This includes the following � Setup MongoDB in the cloud � Gen.pdfThis includes the following � Setup MongoDB in the cloud � Gen.pdf
This includes the following � Setup MongoDB in the cloud � Gen.pdfakaluza07
 
The Xerox Alto42 Imagine the value of cornering the technological ma.pdf
The Xerox Alto42 Imagine the value of cornering the technological ma.pdfThe Xerox Alto42 Imagine the value of cornering the technological ma.pdf
The Xerox Alto42 Imagine the value of cornering the technological ma.pdfakaluza07
 
The java code works, I just need it to display the results as in t.pdf
The java code works, I just need it to display the results as in t.pdfThe java code works, I just need it to display the results as in t.pdf
The java code works, I just need it to display the results as in t.pdfakaluza07
 
The first assignment is about assessing the feasibility of the proje.pdf
The first assignment is about assessing the feasibility of the proje.pdfThe first assignment is about assessing the feasibility of the proje.pdf
The first assignment is about assessing the feasibility of the proje.pdfakaluza07
 
Starter code provided below answer should be in C code please.Star.pdf
Starter code provided below answer should be in C code please.Star.pdfStarter code provided below answer should be in C code please.Star.pdf
Starter code provided below answer should be in C code please.Star.pdfakaluza07
 

More from akaluza07 (9)

Suppose a division of Washington Instruments Incorporated that sells.pdf
Suppose a division of Washington Instruments Incorporated that sells.pdfSuppose a division of Washington Instruments Incorporated that sells.pdf
Suppose a division of Washington Instruments Incorporated that sells.pdf
 
Use the ER Diagram that you created in your Homework Assignment ER .pdf
Use the ER Diagram that you created in your Homework Assignment ER .pdfUse the ER Diagram that you created in your Homework Assignment ER .pdf
Use the ER Diagram that you created in your Homework Assignment ER .pdf
 
Use the ER Diagram that you created in your Homework Assignment ER.pdf
Use the ER Diagram that you created in your Homework Assignment  ER.pdfUse the ER Diagram that you created in your Homework Assignment  ER.pdf
Use the ER Diagram that you created in your Homework Assignment ER.pdf
 
This is to test a balanced tree. I need help testing an unbalanced t.pdf
This is to test a balanced tree. I need help testing an unbalanced t.pdfThis is to test a balanced tree. I need help testing an unbalanced t.pdf
This is to test a balanced tree. I need help testing an unbalanced t.pdf
 
This includes the following � Setup MongoDB in the cloud � Gen.pdf
This includes the following � Setup MongoDB in the cloud � Gen.pdfThis includes the following � Setup MongoDB in the cloud � Gen.pdf
This includes the following � Setup MongoDB in the cloud � Gen.pdf
 
The Xerox Alto42 Imagine the value of cornering the technological ma.pdf
The Xerox Alto42 Imagine the value of cornering the technological ma.pdfThe Xerox Alto42 Imagine the value of cornering the technological ma.pdf
The Xerox Alto42 Imagine the value of cornering the technological ma.pdf
 
The java code works, I just need it to display the results as in t.pdf
The java code works, I just need it to display the results as in t.pdfThe java code works, I just need it to display the results as in t.pdf
The java code works, I just need it to display the results as in t.pdf
 
The first assignment is about assessing the feasibility of the proje.pdf
The first assignment is about assessing the feasibility of the proje.pdfThe first assignment is about assessing the feasibility of the proje.pdf
The first assignment is about assessing the feasibility of the proje.pdf
 
Starter code provided below answer should be in C code please.Star.pdf
Starter code provided below answer should be in C code please.Star.pdfStarter code provided below answer should be in C code please.Star.pdf
Starter code provided below answer should be in C code please.Star.pdf
 

Recently uploaded

Roles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in PharmacovigilanceRoles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in PharmacovigilanceSamikshaHamane
 
Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)Mark Reed
 
Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17Celine George
 
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdf
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdfAMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdf
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdfphamnguyenenglishnb
 
Gas measurement O2,Co2,& ph) 04/2024.pptx
Gas measurement O2,Co2,& ph) 04/2024.pptxGas measurement O2,Co2,& ph) 04/2024.pptx
Gas measurement O2,Co2,& ph) 04/2024.pptxDr.Ibrahim Hassaan
 
Earth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatEarth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatYousafMalik24
 
Types of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptxTypes of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptxEyham Joco
 
Planning a health career 4th Quarter.pptx
Planning a health career 4th Quarter.pptxPlanning a health career 4th Quarter.pptx
Planning a health career 4th Quarter.pptxLigayaBacuel1
 
EPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptxEPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptxRaymartEstabillo3
 
Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Celine George
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxNirmalaLoungPoorunde1
 
Keynote by Prof. Wurzer at Nordex about IP-design
Keynote by Prof. Wurzer at Nordex about IP-designKeynote by Prof. Wurzer at Nordex about IP-design
Keynote by Prof. Wurzer at Nordex about IP-designMIPLM
 
Full Stack Web Development Course for Beginners
Full Stack Web Development Course  for BeginnersFull Stack Web Development Course  for Beginners
Full Stack Web Development Course for BeginnersSabitha Banu
 
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdfLike-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdfMr Bounab Samir
 
Grade 9 Q4-MELC1-Active and Passive Voice.pptx
Grade 9 Q4-MELC1-Active and Passive Voice.pptxGrade 9 Q4-MELC1-Active and Passive Voice.pptx
Grade 9 Q4-MELC1-Active and Passive Voice.pptxChelloAnnAsuncion2
 
Romantic Opera MUSIC FOR GRADE NINE pptx
Romantic Opera MUSIC FOR GRADE NINE pptxRomantic Opera MUSIC FOR GRADE NINE pptx
Romantic Opera MUSIC FOR GRADE NINE pptxsqpmdrvczh
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon AUnboundStockton
 
What is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERPWhat is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERPCeline George
 

Recently uploaded (20)

Roles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in PharmacovigilanceRoles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in Pharmacovigilance
 
Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)
 
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
 
Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17
 
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdf
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdfAMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdf
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdf
 
Gas measurement O2,Co2,& ph) 04/2024.pptx
Gas measurement O2,Co2,& ph) 04/2024.pptxGas measurement O2,Co2,& ph) 04/2024.pptx
Gas measurement O2,Co2,& ph) 04/2024.pptx
 
Earth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatEarth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice great
 
Types of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptxTypes of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptx
 
Planning a health career 4th Quarter.pptx
Planning a health career 4th Quarter.pptxPlanning a health career 4th Quarter.pptx
Planning a health career 4th Quarter.pptx
 
EPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptxEPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptx
 
Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptx
 
Keynote by Prof. Wurzer at Nordex about IP-design
Keynote by Prof. Wurzer at Nordex about IP-designKeynote by Prof. Wurzer at Nordex about IP-design
Keynote by Prof. Wurzer at Nordex about IP-design
 
Full Stack Web Development Course for Beginners
Full Stack Web Development Course  for BeginnersFull Stack Web Development Course  for Beginners
Full Stack Web Development Course for Beginners
 
Rapple "Scholarly Communications and the Sustainable Development Goals"
Rapple "Scholarly Communications and the Sustainable Development Goals"Rapple "Scholarly Communications and the Sustainable Development Goals"
Rapple "Scholarly Communications and the Sustainable Development Goals"
 
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdfLike-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
 
Grade 9 Q4-MELC1-Active and Passive Voice.pptx
Grade 9 Q4-MELC1-Active and Passive Voice.pptxGrade 9 Q4-MELC1-Active and Passive Voice.pptx
Grade 9 Q4-MELC1-Active and Passive Voice.pptx
 
Romantic Opera MUSIC FOR GRADE NINE pptx
Romantic Opera MUSIC FOR GRADE NINE pptxRomantic Opera MUSIC FOR GRADE NINE pptx
Romantic Opera MUSIC FOR GRADE NINE pptx
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon A
 
What is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERPWhat is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERP
 

Submit1) Java Files2) Doc file with the following contents.pdf

  • 1. Submit: 1) Java Files 2) Doc file with the following contents: //************************** SLL.java ********************************* // a generic 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; }
  • 2. 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;
  • 3. 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;
  • 4. } 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; } } public class SLL_Driver { public static void main(String[] args) { SLL myList = new SLL(); String[] cityNames = {"Jubail", "Riyadh", "Abha", "Dammam", "Taif"}; for(int i = 0; i < cityNames.length; i++) myList.addToHead(cityNames[i]); System.out.println("The list is: " + myList); System.out.println("It is " + myList.contains("Dammam") + " that the list contains Dammam."); System.out.println("It is " + myList.contains("Jeddah") + " that the list contains Jeddah."); } } // Java program to implement a queue using an array public class QueueAsArray { private int front, rear, capacity; private T[] queue;
  • 5. public QueueAsArray(int capacity) { front = rear = -1; this.capacity = capacity; queue = (T[]) new Object[capacity]; } public boolean isEmpty(){ return front == -1; } public boolean isFull(){ return rear == capacity - 1; } // function to insert an element at the rear of the queue public void enqueue(T data) { if (isFull()) throw new UnsupportedOperationException("Queue is full!"); if(isEmpty()) front++; rear++; queue[rear] = data; } public T dequeue() { if (isEmpty()) throw new UnsupportedOperationException("Queue is empty!"); T temp = queue[front]; if (rear == 0) { rear = front = -1; } else{ for(int i = 0; i <= rear - 1; i++) { queue[i] = queue[i + 1]; }
  • 6. rear--; } return temp; } public boolean search(T e){ if (isEmpty()) throw new UnsupportedOperationException("Queue is empty!"); for(int i = 0; i <= rear; i++) if(e.equals(queue[i])) return true; return false; } public String toString() { if (isEmpty()) throw new UnsupportedOperationException("Queue is empty!"); String str = ""; for (int i = 0; i <= rear; i++) { str = str + queue[i] + " "; } return str; } public T peek() { if (isEmpty()) throw new UnsupportedOperationException("Queue is empty!"); return queue[front]; } } King Fahd University of Petroleum & Minerals College of Computer Science and Engineering Information and Computer Science Department ICS 202 - Data Structures
  • 7. Recursion Objectives The objective of this lab is to design and implement recursive programs. Outcomes After completing this Lab, students are expected to: Design recursive solutions. - Implement recursive methods. Lab Tasks 1. (a) Comment the iterative public boolean contains(Element e) method of the given SLL class then implement it as a recursive method. Use appropriate helper method in your solution. (c) Use the given test program to test your recursive methods. Sample program run: The list is: [ Taif Dammam Abha Riyadh Jubail ] It is true that the list contains Dammam. It is false that the list contains Jeddah. 2. (a) Comment the iterative public T dequeue () method of the given class QueueAsArray then implement it as a recursive method. Use an appropriate helper method in your solution. (b) Write a test program to test the recursive dequeue method. Sample program run: The queue is: 6020403070 First dequeued element is: 60 Second dequeued element is: 20 After two node deletion the queue is: 403070 Element at queue front is: 4