Need help with your Discussion

Get a timely done, PLAGIARISM-FREE paper
from our highly-qualified writers!

glass
pen
clip
papers
heaphones

The Private String Search and Private Void Process Analysis

The Private String Search and Private Void Process Analysis

The Private String Search and Private Void Process Analysis

Description

Write an efficient xxxxxH5.java program that:

a) Reads n idno and name from input file and inserts them in a BST. // 

b) Print inorder, preorder and postorder of the BST in a user friendly form by modifying inorder, preorder and postorder methods. // 

c) Reads m idno from input file and query the BST. // 

To compile: javac xxxxxH5.java

To execute: java xxxxxH5  20           5          input.txt

A sample input is as follow:

206 Yashir       356 Ryan                   311 Ruth          117 Morgan 341 Mard                 251 Losak

266 Kelly                     371 Ramir     258 Qu                         176 Park                   100 Wesley             288 Victor

161 Sergio       146 Saman   303 Sahil                   228 Saber                333 Saad                              221 Kagen

318 John                     122 Jian                    

243 258 100 117 363

Save the following java program into xxxxxH4.java and just complete the required methods and do not modify main method, except writing your name in line 176.

 1 // CSUN COMP 282 Sp 22, Homework-5

 2 // Implementing Binary Search Tree (BST)

 3 // Author: G. Dastghaiby Fard

 4

 5 import java.io.*;

 6 import java.util.*;

 7

 8 public class xxxxxH5{ 

 9     //root is a pointer to root of the BST     

10     node root = null;

11   

12      //use a short word for prt to save typing

13     PrintStream prt = System.out;    

14     

15      // class node

16      private class node {

17                  int id;

18                  String name;             

19                  node ll, rl;  //left and right link

20                  // node  constructor

21                  node(int myid, String myname) {

22                              id   = myid;

23                              name = myname;

24                              rl = ll = null;

25                  }  //end node constructor

26      }// end class node

27

28      //inorder traversal of BST

29      private void preorder(){

30                  if (root == null){

31                              prt.printf (“ntBST is empty, So no preorder traversal.”);                     

32                              return;

33                  }

34                  prt.printf (“ntPreorder of BST is as follow:n”);

35                  preorder(root);

36      }// end preorder()  

37   

38      //preorder traversal from node t

39      private void preorder(node t){

40                  //complete this method  

41      } //end preorder traversal from node t

42

43      //inorder traversal of BST

44      private void inorder(){

45                  if (root == null){

46                              prt.printf (“ntBST is empty, So no inorder traversal.”);                        

47                              return;

48                  }

49                  prt.printf (“ntInorder of BST is as follow:n”);

50                  inorder(root);

51      }// end inorder()

52   

53      //inorder traversal from node t

54      private void inorder(node t){

55                  //complete this method  

56      } //end inorder traversal from node t

57

58      //postorder traversal of BST

59      private void postorder(){

60                  if (root == null){

61                              prt.printf (“ntBST is empty, So no postorder traversal.”);                   

62                              return;

63                  }

64                  prt.printf (“ntpostorder of BST is as follow:n”);

65                  postorder(root);

66      }// end postorder()

67   

68      //postorder traversal from node t

69      private void postorder(node t){

70                  //complete this method  

71      } //end postorder traversal from node t

72

73    //insert myid and myname in the BST

74      private void insert(int myid, String myname){

75                  if (root == null){

76                              //Allocate space and store myid, myname

77                              root = new node(myid, myname);

78                              return;

79                  }// end if

80                  insert(myid, myname, root);

81      } // end insert(myid, myname)

82

83      //insert myid and myname in the BST from node t

84      private void insert(int myid, String myname, node t){

85                  //Complete this method

86      }  // end insert(myid, myname)

87

88      // search for myid in the BST

89      private String search(int myid){

90                  prt.printf(“ntSearch for %d in the BST: “, myid);

91                  if (root == null){//BST is empty

92                              prt.printf (“tSorry, BST is empty.”);                  

93                              return null;

94                  }

95                  return search(myid, root);

96      } // end search (int myid)  

97   

98      // search for myid in the BST from node t if found return its name

99      private String search(int myid, node t){

100                 //complete this method  

101                 return null;   

102     } // end search (int myid, node t)

103

104

105     // process method for BST insert and search

106     private void process(int n, int m, String fn){

107                 int i, myid, k;

108                 String myname;

109                 prt.print(“tJava program to:ntInsert n id and name into an empty BST,” +

110                 ” printing 3 traversals ntcontents of the BST and” +

111                 ” searching m id in the BST.”);   

112                 try{

113                             Scanner inf = new Scanner(new File(fn));

114                             prt.printf(“ntInsert %d id and name into BST.nt”, n);

115                             // insert n id and name into BST

116                             for (i = 1; i <= n; i++) {

117                                         //read next id and name

118                                         myid = inf.nextInt(); 

119                                         myname = inf.next(); 

120                                         // insert id and name in the bst

121                                         prt.printf(“%2d:%3d, %-10s”, i, myid, myname);

122                                         if (i % 5 == 0) prt.printf(“nt”);

123                                         insert(myid, myname); 

124                             } // end for

125

126                             // print 3 travesals of the BST

127                             preorder();              

128                             inorder();                 

129                             postorder();            

130                              

131                            prt.printf(“ntSearch %2d id in the BST.”, m);

132                             // search for nsrch id in the BST

133                             for (i = 1; i <= m; i++) {

134                                         // read next word

135                                         myid = inf.nextInt(); 

136                                         // search for myid in the bst

137                                         myname = search(myid); 

138                                         if (myname != null)

139                                                     prt.printf(” Found: %s”, myname);

140                                         else

141                                                     prt.printf(” NOT Found.”);

142                             } // end for

143                             //close input file

144                             inf.close();

145                 } catch (Exception e) {prt.print(“nRead Error… ” + e);}              

146     } //end process method

147  

148  

149     //  main method

150     public static void main(String args[]) throws Exception{

151                 int m, n, cnt = args.length; // get no. of atguments

152                 String fn;

153                 if (cnt < 3)

154                     System.out.printf(“ntOOOPS Invalid No. of aguments!”+

155                             “ntTO Execute: java xxxxxH5 20  10  input.txt”);

156                 else {

157                             // get no. of elements to insert

158                             n = Integer.parseInt(args[0]);

159                            

160                             // get no. of elements to search

161                             m = Integer.parseInt(args[1]);

162                            

163                             // get input file name

164                             fn = args[2];

165                                                                

166                             System.out.printf(“nt n = %d, m = %d, fn=%s”,

167                             n, m, fn);

168                            

169                             // create an instance of H1282 class

170                             xxxxxH5 bst = new xxxxxH5();

171

172                             // call process method

173                             bst.process(n, m, fn);

174

175                             //MAKE SURE TO WRITE YOUR NAME IN NEXT LINE                

176                             System.out.printf(“ntAuthor: Gh. Dastghaibyfard Date: ” +

177                             java.time.LocalDate.now());

178                 }

179    } // end main

180 } // end class xxxxxH5

Have a similar assignment? "Place an order for your assignment and have exceptional work written by our team of experts, guaranteeing you A results."

Order Solution Now

Our Service Charter


1. Professional & Expert Writers: Eminence Papers only hires the best. Our writers are specially selected and recruited, after which they undergo further training to perfect their skills for specialization purposes. Moreover, our writers are holders of masters and Ph.D. degrees. They have impressive academic records, besides being native English speakers.

2. Top Quality Papers: Our customers are always guaranteed of papers that exceed their expectations. All our writers have +5 years of experience. This implies that all papers are written by individuals who are experts in their fields. In addition, the quality team reviews all the papers before sending them to the customers.

3. Plagiarism-Free Papers: All papers provided by Eminence Papers are written from scratch. Appropriate referencing and citation of key information are followed. Plagiarism checkers are used by the Quality assurance team and our editors just to double-check that there are no instances of plagiarism.

4. Timely Delivery: Time wasted is equivalent to a failed dedication and commitment. Eminence Papers are known for the timely delivery of any pending customer orders. Customers are well informed of the progress of their papers to ensure they keep track of what the writer is providing before the final draft is sent for grading.

5. Affordable Prices: Our prices are fairly structured to fit in all groups. Any customer willing to place their assignments with us can do so at very affordable prices. In addition, our customers enjoy regular discounts and bonuses.

6. 24/7 Customer Support: At Eminence Papers, we have put in place a team of experts who answer all customer inquiries promptly. The best part is the ever-availability of the team. Customers can make inquiries anytime.

We Can Write It for You! Enjoy 20% OFF on This Order. Use Code SAVE20

Stuck with your Assignment?

Enjoy 20% OFF Today
Use code SAVE20