SlideShare a Scribd company logo
a) Complete both insert and delete methods. If it works correctly 100 points each.
b) Do not call the search method in delete method.
c) Make sure to write your name in main method.
d) DO NOT MODIFY PROCESS METHOD.
3- Create a proper input file with respect to process method to test all cases in both
insert and delete methods.
4- Compile and execute your program at the command prompt. Check your output, if it
is correct
//xxxxxH5.java is linked list implementation of lstinterface.
//Eliminate count form both insert and delete methods
// If works correctly, 200 points
import java.util.*;
import java.io.*;
//lstinterface is an interface
public class xxxxxH5 implements lstinterface {
// xxxxxH5 class variables
//head is a pointer to beginning of linked list
private node head = null;
//use prt for System.out to save typing
PrintStream prt = System.out;
// class node
private class node{
// class node variables
int data;
node rlink; //right link
// class node constructor
node(int x){
data = x;
rlink = null;
} // end class node constructor
}// class node
// insert x at position p,
// if successful return 1 otherwise return 0
public int insert(int x, int p){
prt.printf("nttInsert %5d at position %2d:", x, p);
// complete this method
return 0; // successful insertion
} // end insert
// delete x at position p
// if successful return 1 otherwise return 0
public int delete(int p){
prt.printf("nttDelete element at position %2d:", p);
// complete this method
return 0; // successful insertion
} // end delete
// sequential serach for x in the list
// if successful return its position otherwise return 0;
public int search(int x){
// Local variables
node cur;
prt.printf("nttSearch for %5d:", x);
// Complete the rest of the method
int pos = 0;
for (cur = head; cur != null ; cur = cur.rlink){
pos ++;
if (cur.data == x){
prt.printf(" Found at position %2d, ", pos);
return pos;
} // end if
} // end for
prt.printf(" Not Found.");
return 0; // x is not found.
} // end search
// print list elements formatted
public void printlst() {
// Local variables
node cur;
prt.printf("ntList contents: ");
for (cur = head; cur != null ; cur = cur.rlink)
prt.printf("%5d,", cur.data);
// end for
} // end printlst
// insert delete and search in the list
private void process(String fn){
// Local variables
int j, ins, del, srch, k, p;
int x;
prt.printf("tLinked List implementation of int list without"+
//ntusing count, gets input file name from method argument, then
reads:"+
"ntinteger No. of elements to insert(ins)"+
" followed by elements to insert and their positions,"+
"ntinteger No. of elements to search(srch) followed by element to
search"+
"ntinteger No. of elements to delete(del) followed by position of"+
"elements to delete" +
"nttTo compile: javac xxxxxH5.java" +
"nttTo execute: java xxxxxH5 inputfilename");
try{
// open input file
Scanner inf = new Scanner(new File(fn));
//read no. of elements to insert
ins = inf.nextInt();
prt.printf("ntInsert %d elements in the list.", ins);
for(j = 1; j <= ins; j++){
x = inf.nextInt(); // read x
p = inf.nextInt(); // read position
k = insert(x, p); //insert x at position p
} // end for
printlst();//print list elements
//read no. of elements to search in list
srch = inf.nextInt();
prt.printf("ntSearch for %d elements in list.", srch);
for(j = 1; j <= srch; j++){
x = inf.nextInt(); // read x to serach
k = search(x); //delete position p
}// end for
//read no. of positions to delete from list
del = inf.nextInt();
prt.printf("ntDelete %d elements from list.", del);
for(j = 1; j <= del; j++){
p = inf.nextInt(); // read position
k = delete(p); //delete position p
}// end for
printlst();//print linked list elements
// close input file
inf.close();
}catch (Exception e){prt.printf("ntRead Error! %s", e);}
} // end process
// main method
public static void main(String args[]) throws Exception{
// declare variables
int cnt = args.length; // get no. of arguments
String fname;
if (cnt < 1){
System.out.printf("nntInvalid No. of arguments! EXIT.n");
return;
}
// get input file name
fname = args[0];
//create an instance of a class
xxxxxH5 lst = new xxxxxH5();
lst.process(fname);
//Pleas replace ????????? with your name in next line
System.out.printf("ntAuthor: ????????? Date: %sn",
java.time.LocalDate.now());
} // end main
}// end class xxxxxH5

More Related Content

Similar to a) Complete both insert and delete methods. If it works correctly 10.pdf

-- Write the compiler used- Visual studio or gcc -- Reminder that your.pdf
-- Write the compiler used- Visual studio or gcc -- Reminder that your.pdf-- Write the compiler used- Visual studio or gcc -- Reminder that your.pdf
-- Write the compiler used- Visual studio or gcc -- Reminder that your.pdf
ganisyedtrd
 
Practical_File_Of_Data_Structure.pdf
Practical_File_Of_Data_Structure.pdfPractical_File_Of_Data_Structure.pdf
Practical_File_Of_Data_Structure.pdf
VishwasChoclaty1
 
Write a program that accepts an arithmetic expression of unsigned in.pdf
Write a program that accepts an arithmetic expression of unsigned in.pdfWrite a program that accepts an arithmetic expression of unsigned in.pdf
Write a program that accepts an arithmetic expression of unsigned in.pdf
JUSTSTYLISH3B2MOHALI
 
written in c- please answer the 4 questions and write the functions ba.pdf
written in c- please answer the 4 questions and write the functions ba.pdfwritten in c- please answer the 4 questions and write the functions ba.pdf
written in c- please answer the 4 questions and write the functions ba.pdf
sravi07
 
In C++Add the function min as an abstract function to the classar.pdf
In C++Add the function min as an abstract function to the classar.pdfIn C++Add the function min as an abstract function to the classar.pdf
In C++Add the function min as an abstract function to the classar.pdf
fantoosh1
 
MAINCPP include ltiostreamgt include ltstringgt u.pdf
MAINCPP include ltiostreamgt include ltstringgt u.pdfMAINCPP include ltiostreamgt include ltstringgt u.pdf
MAINCPP include ltiostreamgt include ltstringgt u.pdf
adityastores21
 
please follow all instructions and answer the inbedded questions- and.pdf
please follow all instructions and answer the inbedded questions- and.pdfplease follow all instructions and answer the inbedded questions- and.pdf
please follow all instructions and answer the inbedded questions- and.pdf
Ian5L3Allanm
 
7 functions
7  functions7  functions
7 functions
MomenMostafa
 
Written in C- requires linked lists- Please answer the 4 questions and.pdf
Written in C- requires linked lists- Please answer the 4 questions and.pdfWritten in C- requires linked lists- Please answer the 4 questions and.pdf
Written in C- requires linked lists- Please answer the 4 questions and.pdf
sravi07
 
Written in C- requires linked lists- Please answer the 4 questions and (1).pdf
Written in C- requires linked lists- Please answer the 4 questions and (1).pdfWritten in C- requires linked lists- Please answer the 4 questions and (1).pdf
Written in C- requires linked lists- Please answer the 4 questions and (1).pdf
sravi07
 
CppQuickRef.pdf
CppQuickRef.pdfCppQuickRef.pdf
CppQuickRef.pdf
kurimaru1
 
C++ QUICK REFERENCE.pdf
C++ QUICK REFERENCE.pdfC++ QUICK REFERENCE.pdf
C++ QUICK REFERENCE.pdf
fqerwqdfad
 
Cquestions
Cquestions Cquestions
Cquestions
mohamed sikander
 
#ifndef MYLIST_H_ #define MYLIST_H_#includeiostream #include.docx
#ifndef MYLIST_H_ #define MYLIST_H_#includeiostream #include.docx#ifndef MYLIST_H_ #define MYLIST_H_#includeiostream #include.docx
#ifndef MYLIST_H_ #define MYLIST_H_#includeiostream #include.docx
ajoy21
 
01 list using array
01 list using array01 list using array
01 list using array
SivakamiRaja1
 
Data Structure using C
Data Structure using CData Structure using C
Data Structure using C
Bilal Mirza
 
Program of sorting using shell sort #include stdio.h #de.pdf
 Program of sorting using shell sort  #include stdio.h #de.pdf Program of sorting using shell sort  #include stdio.h #de.pdf
Program of sorting using shell sort #include stdio.h #de.pdf
anujmkt
 

Similar to a) Complete both insert and delete methods. If it works correctly 10.pdf (20)

-- Write the compiler used- Visual studio or gcc -- Reminder that your.pdf
-- Write the compiler used- Visual studio or gcc -- Reminder that your.pdf-- Write the compiler used- Visual studio or gcc -- Reminder that your.pdf
-- Write the compiler used- Visual studio or gcc -- Reminder that your.pdf
 
Practical_File_Of_Data_Structure.pdf
Practical_File_Of_Data_Structure.pdfPractical_File_Of_Data_Structure.pdf
Practical_File_Of_Data_Structure.pdf
 
Final ds record
Final ds recordFinal ds record
Final ds record
 
week-14x
week-14xweek-14x
week-14x
 
Write a program that accepts an arithmetic expression of unsigned in.pdf
Write a program that accepts an arithmetic expression of unsigned in.pdfWrite a program that accepts an arithmetic expression of unsigned in.pdf
Write a program that accepts an arithmetic expression of unsigned in.pdf
 
written in c- please answer the 4 questions and write the functions ba.pdf
written in c- please answer the 4 questions and write the functions ba.pdfwritten in c- please answer the 4 questions and write the functions ba.pdf
written in c- please answer the 4 questions and write the functions ba.pdf
 
In C++Add the function min as an abstract function to the classar.pdf
In C++Add the function min as an abstract function to the classar.pdfIn C++Add the function min as an abstract function to the classar.pdf
In C++Add the function min as an abstract function to the classar.pdf
 
MAINCPP include ltiostreamgt include ltstringgt u.pdf
MAINCPP include ltiostreamgt include ltstringgt u.pdfMAINCPP include ltiostreamgt include ltstringgt u.pdf
MAINCPP include ltiostreamgt include ltstringgt u.pdf
 
please follow all instructions and answer the inbedded questions- and.pdf
please follow all instructions and answer the inbedded questions- and.pdfplease follow all instructions and answer the inbedded questions- and.pdf
please follow all instructions and answer the inbedded questions- and.pdf
 
7 functions
7  functions7  functions
7 functions
 
Written in C- requires linked lists- Please answer the 4 questions and.pdf
Written in C- requires linked lists- Please answer the 4 questions and.pdfWritten in C- requires linked lists- Please answer the 4 questions and.pdf
Written in C- requires linked lists- Please answer the 4 questions and.pdf
 
Written in C- requires linked lists- Please answer the 4 questions and (1).pdf
Written in C- requires linked lists- Please answer the 4 questions and (1).pdfWritten in C- requires linked lists- Please answer the 4 questions and (1).pdf
Written in C- requires linked lists- Please answer the 4 questions and (1).pdf
 
CppQuickRef.pdf
CppQuickRef.pdfCppQuickRef.pdf
CppQuickRef.pdf
 
C++ QUICK REFERENCE.pdf
C++ QUICK REFERENCE.pdfC++ QUICK REFERENCE.pdf
C++ QUICK REFERENCE.pdf
 
Cquestions
Cquestions Cquestions
Cquestions
 
week-19x
week-19xweek-19x
week-19x
 
#ifndef MYLIST_H_ #define MYLIST_H_#includeiostream #include.docx
#ifndef MYLIST_H_ #define MYLIST_H_#includeiostream #include.docx#ifndef MYLIST_H_ #define MYLIST_H_#includeiostream #include.docx
#ifndef MYLIST_H_ #define MYLIST_H_#includeiostream #include.docx
 
01 list using array
01 list using array01 list using array
01 list using array
 
Data Structure using C
Data Structure using CData Structure using C
Data Structure using C
 
Program of sorting using shell sort #include stdio.h #de.pdf
 Program of sorting using shell sort  #include stdio.h #de.pdf Program of sorting using shell sort  #include stdio.h #de.pdf
Program of sorting using shell sort #include stdio.h #de.pdf
 

More from MAYANKBANSAL1981

Business management 1. True or False Diversification is when compa.pdf
Business management  1. True or False Diversification is when compa.pdfBusiness management  1. True or False Diversification is when compa.pdf
Business management 1. True or False Diversification is when compa.pdf
MAYANKBANSAL1981
 
Complete in JavaCardApp.javapublic class CardApp { private.pdf
Complete in JavaCardApp.javapublic class CardApp {   private.pdfComplete in JavaCardApp.javapublic class CardApp {   private.pdf
Complete in JavaCardApp.javapublic class CardApp { private.pdf
MAYANKBANSAL1981
 
Change to oop formatimport java.util.Scanner;import java.io.;.pdf
Change to oop formatimport java.util.Scanner;import java.io.;.pdfChange to oop formatimport java.util.Scanner;import java.io.;.pdf
Change to oop formatimport java.util.Scanner;import java.io.;.pdf
MAYANKBANSAL1981
 
Case Project 2-1 Advance PreparationsThe IT managers from Chicago.pdf
Case Project 2-1 Advance PreparationsThe IT managers from Chicago.pdfCase Project 2-1 Advance PreparationsThe IT managers from Chicago.pdf
Case Project 2-1 Advance PreparationsThe IT managers from Chicago.pdf
MAYANKBANSAL1981
 
Can some one redo this code without the try-catch and an alternative.pdf
Can some one redo this code without the try-catch and an alternative.pdfCan some one redo this code without the try-catch and an alternative.pdf
Can some one redo this code without the try-catch and an alternative.pdf
MAYANKBANSAL1981
 
Banks are singled out for special attention in the financial sys.pdf
Banks are singled out for special attention in the financial sys.pdfBanks are singled out for special attention in the financial sys.pdf
Banks are singled out for special attention in the financial sys.pdf
MAYANKBANSAL1981
 
ASSETS LIABILITIES Cash $10,000 Accounts payable $12,000 Accounts re.pdf
ASSETS LIABILITIES Cash $10,000 Accounts payable $12,000 Accounts re.pdfASSETS LIABILITIES Cash $10,000 Accounts payable $12,000 Accounts re.pdf
ASSETS LIABILITIES Cash $10,000 Accounts payable $12,000 Accounts re.pdf
MAYANKBANSAL1981
 
A. Monitoring Internet Endpoints and Bandwidth Consumption1. NetFl.pdf
A. Monitoring Internet Endpoints and Bandwidth Consumption1. NetFl.pdfA. Monitoring Internet Endpoints and Bandwidth Consumption1. NetFl.pdf
A. Monitoring Internet Endpoints and Bandwidth Consumption1. NetFl.pdf
MAYANKBANSAL1981
 
About your clientName Samantha BensonAge 54Marital status .pdf
About your clientName Samantha BensonAge 54Marital status .pdfAbout your clientName Samantha BensonAge 54Marital status .pdf
About your clientName Samantha BensonAge 54Marital status .pdf
MAYANKBANSAL1981
 
About your clientName Samantha Benson Age 54 Marital status Ma.pdf
About your clientName Samantha Benson Age 54 Marital status Ma.pdfAbout your clientName Samantha Benson Age 54 Marital status Ma.pdf
About your clientName Samantha Benson Age 54 Marital status Ma.pdf
MAYANKBANSAL1981
 
About your client Name Samantha Benson Age 54 Marital status Ma.pdf
About your client Name Samantha Benson Age 54 Marital status Ma.pdfAbout your client Name Samantha Benson Age 54 Marital status Ma.pdf
About your client Name Samantha Benson Age 54 Marital status Ma.pdf
MAYANKBANSAL1981
 
About your client Name Samantha BensonAge 54Marital status.pdf
About your client Name Samantha BensonAge 54Marital status.pdfAbout your client Name Samantha BensonAge 54Marital status.pdf
About your client Name Samantha BensonAge 54Marital status.pdf
MAYANKBANSAL1981
 
Answer the following prompts 1The InstantRide Management team foun.pdf
Answer the following prompts 1The InstantRide Management team foun.pdfAnswer the following prompts 1The InstantRide Management team foun.pdf
Answer the following prompts 1The InstantRide Management team foun.pdf
MAYANKBANSAL1981
 
Advanced level school Python programming. Need helps. Thank.pdf
Advanced level school Python programming.  Need helps. Thank.pdfAdvanced level school Python programming.  Need helps. Thank.pdf
Advanced level school Python programming. Need helps. Thank.pdf
MAYANKBANSAL1981
 

More from MAYANKBANSAL1981 (14)

Business management 1. True or False Diversification is when compa.pdf
Business management  1. True or False Diversification is when compa.pdfBusiness management  1. True or False Diversification is when compa.pdf
Business management 1. True or False Diversification is when compa.pdf
 
Complete in JavaCardApp.javapublic class CardApp { private.pdf
Complete in JavaCardApp.javapublic class CardApp {   private.pdfComplete in JavaCardApp.javapublic class CardApp {   private.pdf
Complete in JavaCardApp.javapublic class CardApp { private.pdf
 
Change to oop formatimport java.util.Scanner;import java.io.;.pdf
Change to oop formatimport java.util.Scanner;import java.io.;.pdfChange to oop formatimport java.util.Scanner;import java.io.;.pdf
Change to oop formatimport java.util.Scanner;import java.io.;.pdf
 
Case Project 2-1 Advance PreparationsThe IT managers from Chicago.pdf
Case Project 2-1 Advance PreparationsThe IT managers from Chicago.pdfCase Project 2-1 Advance PreparationsThe IT managers from Chicago.pdf
Case Project 2-1 Advance PreparationsThe IT managers from Chicago.pdf
 
Can some one redo this code without the try-catch and an alternative.pdf
Can some one redo this code without the try-catch and an alternative.pdfCan some one redo this code without the try-catch and an alternative.pdf
Can some one redo this code without the try-catch and an alternative.pdf
 
Banks are singled out for special attention in the financial sys.pdf
Banks are singled out for special attention in the financial sys.pdfBanks are singled out for special attention in the financial sys.pdf
Banks are singled out for special attention in the financial sys.pdf
 
ASSETS LIABILITIES Cash $10,000 Accounts payable $12,000 Accounts re.pdf
ASSETS LIABILITIES Cash $10,000 Accounts payable $12,000 Accounts re.pdfASSETS LIABILITIES Cash $10,000 Accounts payable $12,000 Accounts re.pdf
ASSETS LIABILITIES Cash $10,000 Accounts payable $12,000 Accounts re.pdf
 
A. Monitoring Internet Endpoints and Bandwidth Consumption1. NetFl.pdf
A. Monitoring Internet Endpoints and Bandwidth Consumption1. NetFl.pdfA. Monitoring Internet Endpoints and Bandwidth Consumption1. NetFl.pdf
A. Monitoring Internet Endpoints and Bandwidth Consumption1. NetFl.pdf
 
About your clientName Samantha BensonAge 54Marital status .pdf
About your clientName Samantha BensonAge 54Marital status .pdfAbout your clientName Samantha BensonAge 54Marital status .pdf
About your clientName Samantha BensonAge 54Marital status .pdf
 
About your clientName Samantha Benson Age 54 Marital status Ma.pdf
About your clientName Samantha Benson Age 54 Marital status Ma.pdfAbout your clientName Samantha Benson Age 54 Marital status Ma.pdf
About your clientName Samantha Benson Age 54 Marital status Ma.pdf
 
About your client Name Samantha Benson Age 54 Marital status Ma.pdf
About your client Name Samantha Benson Age 54 Marital status Ma.pdfAbout your client Name Samantha Benson Age 54 Marital status Ma.pdf
About your client Name Samantha Benson Age 54 Marital status Ma.pdf
 
About your client Name Samantha BensonAge 54Marital status.pdf
About your client Name Samantha BensonAge 54Marital status.pdfAbout your client Name Samantha BensonAge 54Marital status.pdf
About your client Name Samantha BensonAge 54Marital status.pdf
 
Answer the following prompts 1The InstantRide Management team foun.pdf
Answer the following prompts 1The InstantRide Management team foun.pdfAnswer the following prompts 1The InstantRide Management team foun.pdf
Answer the following prompts 1The InstantRide Management team foun.pdf
 
Advanced level school Python programming. Need helps. Thank.pdf
Advanced level school Python programming.  Need helps. Thank.pdfAdvanced level school Python programming.  Need helps. Thank.pdf
Advanced level school Python programming. Need helps. Thank.pdf
 

Recently uploaded

How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...
Jisc
 
Lapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdfLapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdf
Jean Carlos Nunes Paixão
 
Honest Reviews of Tim Han LMA Course Program.pptx
Honest Reviews of Tim Han LMA Course Program.pptxHonest Reviews of Tim Han LMA Course Program.pptx
Honest Reviews of Tim Han LMA Course Program.pptx
timhan337
 
Language Across the Curriculm LAC B.Ed.
Language Across the  Curriculm LAC B.Ed.Language Across the  Curriculm LAC B.Ed.
Language Across the Curriculm LAC B.Ed.
Atul Kumar Singh
 
Unit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdfUnit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdf
Thiyagu K
 
Polish students' mobility in the Czech Republic
Polish students' mobility in the Czech RepublicPolish students' mobility in the Czech Republic
Polish students' mobility in the Czech Republic
Anna Sz.
 
The Accursed House by Émile Gaboriau.pptx
The Accursed House by Émile Gaboriau.pptxThe Accursed House by Émile Gaboriau.pptx
The Accursed House by Émile Gaboriau.pptx
DhatriParmar
 
Home assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdfHome assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdf
Tamralipta Mahavidyalaya
 
A Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in EducationA Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in Education
Peter Windle
 
Instructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptxInstructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptx
Jheel Barad
 
Palestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptxPalestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptx
RaedMohamed3
 
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCECLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
BhavyaRajput3
 
Chapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptxChapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptx
Mohd Adib Abd Muin, Senior Lecturer at Universiti Utara Malaysia
 
Additional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdfAdditional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdf
joachimlavalley1
 
Digital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and ResearchDigital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and Research
Vikramjit Singh
 
The Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official PublicationThe Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official Publication
Delapenabediema
 
Synthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptxSynthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptx
Pavel ( NSTU)
 
678020731-Sumas-y-Restas-Para-Colorear.pdf
678020731-Sumas-y-Restas-Para-Colorear.pdf678020731-Sumas-y-Restas-Para-Colorear.pdf
678020731-Sumas-y-Restas-Para-Colorear.pdf
CarlosHernanMontoyab2
 
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
EugeneSaldivar
 
special B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdfspecial B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdf
Special education needs
 

Recently uploaded (20)

How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...
 
Lapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdfLapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdf
 
Honest Reviews of Tim Han LMA Course Program.pptx
Honest Reviews of Tim Han LMA Course Program.pptxHonest Reviews of Tim Han LMA Course Program.pptx
Honest Reviews of Tim Han LMA Course Program.pptx
 
Language Across the Curriculm LAC B.Ed.
Language Across the  Curriculm LAC B.Ed.Language Across the  Curriculm LAC B.Ed.
Language Across the Curriculm LAC B.Ed.
 
Unit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdfUnit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdf
 
Polish students' mobility in the Czech Republic
Polish students' mobility in the Czech RepublicPolish students' mobility in the Czech Republic
Polish students' mobility in the Czech Republic
 
The Accursed House by Émile Gaboriau.pptx
The Accursed House by Émile Gaboriau.pptxThe Accursed House by Émile Gaboriau.pptx
The Accursed House by Émile Gaboriau.pptx
 
Home assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdfHome assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdf
 
A Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in EducationA Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in Education
 
Instructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptxInstructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptx
 
Palestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptxPalestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptx
 
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCECLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
 
Chapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptxChapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptx
 
Additional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdfAdditional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdf
 
Digital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and ResearchDigital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and Research
 
The Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official PublicationThe Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official Publication
 
Synthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptxSynthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptx
 
678020731-Sumas-y-Restas-Para-Colorear.pdf
678020731-Sumas-y-Restas-Para-Colorear.pdf678020731-Sumas-y-Restas-Para-Colorear.pdf
678020731-Sumas-y-Restas-Para-Colorear.pdf
 
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
 
special B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdfspecial B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdf
 

a) Complete both insert and delete methods. If it works correctly 10.pdf

  • 1. a) Complete both insert and delete methods. If it works correctly 100 points each. b) Do not call the search method in delete method. c) Make sure to write your name in main method. d) DO NOT MODIFY PROCESS METHOD. 3- Create a proper input file with respect to process method to test all cases in both insert and delete methods. 4- Compile and execute your program at the command prompt. Check your output, if it is correct //xxxxxH5.java is linked list implementation of lstinterface. //Eliminate count form both insert and delete methods // If works correctly, 200 points import java.util.*; import java.io.*; //lstinterface is an interface public class xxxxxH5 implements lstinterface { // xxxxxH5 class variables //head is a pointer to beginning of linked list private node head = null; //use prt for System.out to save typing PrintStream prt = System.out; // class node private class node{ // class node variables int data; node rlink; //right link // class node constructor node(int x){ data = x; rlink = null; } // end class node constructor }// class node // insert x at position p, // if successful return 1 otherwise return 0 public int insert(int x, int p){
  • 2. prt.printf("nttInsert %5d at position %2d:", x, p); // complete this method return 0; // successful insertion } // end insert // delete x at position p // if successful return 1 otherwise return 0 public int delete(int p){ prt.printf("nttDelete element at position %2d:", p); // complete this method return 0; // successful insertion } // end delete // sequential serach for x in the list // if successful return its position otherwise return 0; public int search(int x){ // Local variables node cur; prt.printf("nttSearch for %5d:", x); // Complete the rest of the method int pos = 0; for (cur = head; cur != null ; cur = cur.rlink){ pos ++; if (cur.data == x){ prt.printf(" Found at position %2d, ", pos); return pos; } // end if } // end for prt.printf(" Not Found."); return 0; // x is not found. } // end search // print list elements formatted public void printlst() { // Local variables node cur; prt.printf("ntList contents: ");
  • 3. for (cur = head; cur != null ; cur = cur.rlink) prt.printf("%5d,", cur.data); // end for } // end printlst // insert delete and search in the list private void process(String fn){ // Local variables int j, ins, del, srch, k, p; int x; prt.printf("tLinked List implementation of int list without"+ //ntusing count, gets input file name from method argument, then reads:"+ "ntinteger No. of elements to insert(ins)"+ " followed by elements to insert and their positions,"+ "ntinteger No. of elements to search(srch) followed by element to search"+ "ntinteger No. of elements to delete(del) followed by position of"+ "elements to delete" + "nttTo compile: javac xxxxxH5.java" + "nttTo execute: java xxxxxH5 inputfilename"); try{ // open input file Scanner inf = new Scanner(new File(fn)); //read no. of elements to insert ins = inf.nextInt(); prt.printf("ntInsert %d elements in the list.", ins); for(j = 1; j <= ins; j++){ x = inf.nextInt(); // read x p = inf.nextInt(); // read position k = insert(x, p); //insert x at position p } // end for printlst();//print list elements //read no. of elements to search in list srch = inf.nextInt(); prt.printf("ntSearch for %d elements in list.", srch); for(j = 1; j <= srch; j++){
  • 4. x = inf.nextInt(); // read x to serach k = search(x); //delete position p }// end for //read no. of positions to delete from list del = inf.nextInt(); prt.printf("ntDelete %d elements from list.", del); for(j = 1; j <= del; j++){ p = inf.nextInt(); // read position k = delete(p); //delete position p }// end for printlst();//print linked list elements // close input file inf.close(); }catch (Exception e){prt.printf("ntRead Error! %s", e);} } // end process // main method public static void main(String args[]) throws Exception{ // declare variables int cnt = args.length; // get no. of arguments String fname; if (cnt < 1){ System.out.printf("nntInvalid No. of arguments! EXIT.n"); return; } // get input file name fname = args[0]; //create an instance of a class xxxxxH5 lst = new xxxxxH5(); lst.process(fname); //Pleas replace ????????? with your name in next line System.out.printf("ntAuthor: ????????? Date: %sn", java.time.LocalDate.now()); } // end main }// end class xxxxxH5