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

PDF
Implement the interface you wrote for Lab B (EntryWayListInterface)..pdf
PDF
PLEASE MAKE SURE THE PROGRAM IS ASKING FOR INPUT FROM USER TO ADD OR.pdf
PDF
Data structure singly linked list programs VTU Exams
PDF
Lab02kdfshdfgajhdfgajhdfgajhdfgjhadgfasjhdgfjhasdgfjh.pdf
PDF
Write a JAVA LinkedListRec class that has the following methods siz.pdf
PDF
Note             Given Code modified as required and required met.pdf
DOCX
Please complete all the code as per instructions in Java programming.docx
PDF
Hi,I have added the methods and main class as per your requirement.pdf
Implement the interface you wrote for Lab B (EntryWayListInterface)..pdf
PLEASE MAKE SURE THE PROGRAM IS ASKING FOR INPUT FROM USER TO ADD OR.pdf
Data structure singly linked list programs VTU Exams
Lab02kdfshdfgajhdfgajhdfgajhdfgjhadgfasjhdgfjhasdgfjh.pdf
Write a JAVA LinkedListRec class that has the following methods siz.pdf
Note             Given Code modified as required and required met.pdf
Please complete all the code as per instructions in Java programming.docx
Hi,I have added the methods and main class as per your requirement.pdf

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

DOC
Final ds record
PDF
STAGE 2 The Methods 65 points Implement all the methods t.pdf
PDF
For each task, submit your source java code file.(1) Objective Im.pdf
PDF
-JAVA-provide a test class that do the required -you may add met.pdf
PDF
Write a Java Class to Implement a Generic Linked ListYour list mus.pdf
PDF
Please need help on following program using c++ language. Please inc.pdf
PDF
Class DiagramIn the Assignment #10, you are given three files Ass.pdf
PDF
please i need help Im writing a program to test the merge sort alg.pdf
PDF
There are a couple of new methods that you will be writing for this pr.pdf
PDF
Note- Can someone help me with the Public boolean add(E value) method.pdf
PDF
implement the ListLinked ADT (the declaration is given in ListLinked.pdf
PPT
Linked-List with operations and algorithms.ppt
PDF
Practical_File_Of_Data_Structure.pdf
PDF
Data Structure
PDF
#includeiostream #includecstdio #includecstdlib using na.pdf
DOCX
Note- Can someone help me with the private E get(int index- int curren (1).docx
PDF
Complete the provided partial C++ Linked List program. Main.cpp is g.pdf
PDF
–PLS write program in c++Recursive Linked List OperationsWrite a.pdf
Final ds record
STAGE 2 The Methods 65 points Implement all the methods t.pdf
For each task, submit your source java code file.(1) Objective Im.pdf
-JAVA-provide a test class that do the required -you may add met.pdf
Write a Java Class to Implement a Generic Linked ListYour list mus.pdf
Please need help on following program using c++ language. Please inc.pdf
Class DiagramIn the Assignment #10, you are given three files Ass.pdf
please i need help Im writing a program to test the merge sort alg.pdf
There are a couple of new methods that you will be writing for this pr.pdf
Note- Can someone help me with the Public boolean add(E value) method.pdf
implement the ListLinked ADT (the declaration is given in ListLinked.pdf
Linked-List with operations and algorithms.ppt
Practical_File_Of_Data_Structure.pdf
Data Structure
#includeiostream #includecstdio #includecstdlib using na.pdf
Note- Can someone help me with the private E get(int index- int curren (1).docx
Complete the provided partial C++ Linked List program. Main.cpp is g.pdf
–PLS write program in c++Recursive Linked List OperationsWrite a.pdf
Ad

More from MAYANKBANSAL1981 (14)

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

Recently uploaded (20)

PDF
Black Hat USA 2025 - Micro ICS Summit - ICS/OT Threat Landscape
PDF
Complications of Minimal Access Surgery at WLH
PDF
Chapter 2 Heredity, Prenatal Development, and Birth.pdf
PPTX
PPT- ENG7_QUARTER1_LESSON1_WEEK1. IMAGERY -DESCRIPTIONS pptx.pptx
PPTX
Cell Types and Its function , kingdom of life
PDF
Anesthesia in Laparoscopic Surgery in India
PDF
Module 4: Burden of Disease Tutorial Slides S2 2025
PPTX
Introduction-to-Literarature-and-Literary-Studies-week-Prelim-coverage.pptx
PPTX
202450812 BayCHI UCSC-SV 20250812 v17.pptx
PDF
Saundersa Comprehensive Review for the NCLEX-RN Examination.pdf
PDF
OBE - B.A.(HON'S) IN INTERIOR ARCHITECTURE -Ar.MOHIUDDIN.pdf
PDF
O5-L3 Freight Transport Ops (International) V1.pdf
PPTX
Pharmacology of Heart Failure /Pharmacotherapy of CHF
PPTX
1st Inaugural Professorial Lecture held on 19th February 2020 (Governance and...
PPTX
master seminar digital applications in india
PDF
grade 11-chemistry_fetena_net_5883.pdf teacher guide for all student
PDF
A GUIDE TO GENETICS FOR UNDERGRADUATE MEDICAL STUDENTS
PDF
Chinmaya Tiranga quiz Grand Finale.pdf
PDF
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
PDF
Classroom Observation Tools for Teachers
Black Hat USA 2025 - Micro ICS Summit - ICS/OT Threat Landscape
Complications of Minimal Access Surgery at WLH
Chapter 2 Heredity, Prenatal Development, and Birth.pdf
PPT- ENG7_QUARTER1_LESSON1_WEEK1. IMAGERY -DESCRIPTIONS pptx.pptx
Cell Types and Its function , kingdom of life
Anesthesia in Laparoscopic Surgery in India
Module 4: Burden of Disease Tutorial Slides S2 2025
Introduction-to-Literarature-and-Literary-Studies-week-Prelim-coverage.pptx
202450812 BayCHI UCSC-SV 20250812 v17.pptx
Saundersa Comprehensive Review for the NCLEX-RN Examination.pdf
OBE - B.A.(HON'S) IN INTERIOR ARCHITECTURE -Ar.MOHIUDDIN.pdf
O5-L3 Freight Transport Ops (International) V1.pdf
Pharmacology of Heart Failure /Pharmacotherapy of CHF
1st Inaugural Professorial Lecture held on 19th February 2020 (Governance and...
master seminar digital applications in india
grade 11-chemistry_fetena_net_5883.pdf teacher guide for all student
A GUIDE TO GENETICS FOR UNDERGRADUATE MEDICAL STUDENTS
Chinmaya Tiranga quiz Grand Finale.pdf
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
Classroom Observation Tools for Teachers

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