SlideShare a Scribd company logo
1 of 4
Download to read offline
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.pdfganisyedtrd
 
Practical_File_Of_Data_Structure.pdf
Practical_File_Of_Data_Structure.pdfPractical_File_Of_Data_Structure.pdf
Practical_File_Of_Data_Structure.pdfVishwasChoclaty1
 
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.pdfJUSTSTYLISH3B2MOHALI
 
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.pdfsravi07
 
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.pdffantoosh1
 
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.pdfadityastores21
 
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.pdfIan5L3Allanm
 
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.pdfsravi07
 
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).pdfsravi07
 
C++ QUICK REFERENCE.pdf
C++ QUICK REFERENCE.pdfC++ QUICK REFERENCE.pdf
C++ QUICK REFERENCE.pdffqerwqdfad
 
CppQuickRef.pdf
CppQuickRef.pdfCppQuickRef.pdf
CppQuickRef.pdfkurimaru1
 
#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.docxajoy21
 
Data Structure using C
Data Structure using CData Structure using C
Data Structure using CBilal 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.pdfanujmkt
 

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
 
C++ QUICK REFERENCE.pdf
C++ QUICK REFERENCE.pdfC++ QUICK REFERENCE.pdf
C++ QUICK REFERENCE.pdf
 
CppQuickRef.pdf
CppQuickRef.pdfCppQuickRef.pdf
CppQuickRef.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.pdfMAYANKBANSAL1981
 
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.pdfMAYANKBANSAL1981
 
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.;.pdfMAYANKBANSAL1981
 
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.pdfMAYANKBANSAL1981
 
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.pdfMAYANKBANSAL1981
 
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.pdfMAYANKBANSAL1981
 
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.pdfMAYANKBANSAL1981
 
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.pdfMAYANKBANSAL1981
 
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 .pdfMAYANKBANSAL1981
 
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.pdfMAYANKBANSAL1981
 
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.pdfMAYANKBANSAL1981
 
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.pdfMAYANKBANSAL1981
 
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.pdfMAYANKBANSAL1981
 
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.pdfMAYANKBANSAL1981
 

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

CELL CYCLE Division Science 8 quarter IV.pptx
CELL CYCLE Division Science 8 quarter IV.pptxCELL CYCLE Division Science 8 quarter IV.pptx
CELL CYCLE Division Science 8 quarter IV.pptxJiesonDelaCerna
 
Roles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in PharmacovigilanceRoles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in PharmacovigilanceSamikshaHamane
 
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Celine George
 
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...M56BOOKSTORE PRODUCT/SERVICE
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxSayali Powar
 
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
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentInMediaRes1
 
Biting mechanism of poisonous snakes.pdf
Biting mechanism of poisonous snakes.pdfBiting mechanism of poisonous snakes.pdf
Biting mechanism of poisonous snakes.pdfadityarao40181
 
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
 
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
 
MARGINALIZATION (Different learners in Marginalized Group
MARGINALIZATION (Different learners in Marginalized GroupMARGINALIZATION (Different learners in Marginalized Group
MARGINALIZATION (Different learners in Marginalized GroupJonathanParaisoCruz
 
Meghan Sutherland In Media Res Media Component
Meghan Sutherland In Media Res Media ComponentMeghan Sutherland In Media Res Media Component
Meghan Sutherland In Media Res Media ComponentInMediaRes1
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptxVS Mahajan Coaching Centre
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)eniolaolutunde
 
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Educationpboyjonauth
 
How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17Celine George
 
Proudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxProudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxthorishapillay1
 
DATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersDATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersSabitha Banu
 

Recently uploaded (20)

CELL CYCLE Division Science 8 quarter IV.pptx
CELL CYCLE Division Science 8 quarter IV.pptxCELL CYCLE Division Science 8 quarter IV.pptx
CELL CYCLE Division Science 8 quarter IV.pptx
 
Roles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in PharmacovigilanceRoles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in Pharmacovigilance
 
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
 
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.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
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media Component
 
Biting mechanism of poisonous snakes.pdf
Biting mechanism of poisonous snakes.pdfBiting mechanism of poisonous snakes.pdf
Biting mechanism of poisonous snakes.pdf
 
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
 
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
 
MARGINALIZATION (Different learners in Marginalized Group
MARGINALIZATION (Different learners in Marginalized GroupMARGINALIZATION (Different learners in Marginalized Group
MARGINALIZATION (Different learners in Marginalized Group
 
Meghan Sutherland In Media Res Media Component
Meghan Sutherland In Media Res Media ComponentMeghan Sutherland In Media Res Media Component
Meghan Sutherland In Media Res Media Component
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)
 
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Education
 
How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17
 
ESSENTIAL of (CS/IT/IS) class 06 (database)
ESSENTIAL of (CS/IT/IS) class 06 (database)ESSENTIAL of (CS/IT/IS) class 06 (database)
ESSENTIAL of (CS/IT/IS) class 06 (database)
 
Proudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxProudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptx
 
DATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersDATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginners
 

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