12/11/2023 0 Comments Sequential search code![]() ![]() * This java expression appends the current element of the node to the * elements of the linkedList and adding them to a stringBuilder, the stringBuilder * This method overrides the toString method by taking all Links this node with the kast nide inserted * This method pushes a new node to the end of the linkedList. * This method is used to determine if the linkedList is empty and returns * to set the size of the linked list to 0. * This constructor is used to the last node of the linked list to null and used Int size //Used to get the size of the linked list ![]() Node lastNode //Used as the last node of the linked list * To change this template file, choose Tools | Templates * To change this license header, choose License Headers in Project Properties. Would a hashmap or linked list be easier for this? If you want to would you look at my class and tell me of beginner mistakes or changes to do? I am trying to improve. I'm trying to do a sequential search on both the name and ID of the customer. Then I do whatever I need to with the linked list. So basically I should read in the file from my customer class and use my linked list class to add each customer as a node. When I store the elements in the linked list I should store them as customer/client objects. So basically I have a customer class and this class has attributes that defines each customer. HIH and if you have any further questions, please feel free to ask. There's very little space overhead, and you can create different orderings with Comparators (). If it's only orderings you're worried about, it's worth remembering that there's absolutely nothing to stop you creating more than one Map - and if you need to access elements in those orders, I'd actually suggest a TreeSet or TreeMap, not a HashMap. ![]() Then your LinkedList becomes a LinkedList, and you can store it in whatever structure you see fit. This is precisely what Java classes were meant for, so just create a class that describes the contents of one element ( Client? Customer?) and convert your input to instances of that class BEFORE you do any sorting/arranging.įurthermore, the fields of that class should be the appropriate type, viz: public final class Client and should contain all the logic for converting Strings (or CSV "elements") to those types. If, however, you mean that you're using an array to store the values of your "element" (name, address, etc), then you're almost certainly doing it WRONG. A LinkedList already contains elements, so why would you feel the need to use arrays as well? Below is an example of the elements in a linked list.Ĭharles Sexton wrote:Of course I used an array to split each element of the list. ![]() I feel like this approach is a little more redundant and maybe their is a better approach for searching for id and name. However I feel like this is inefficient and I would like to use the linked list instead of a hashmap which could be done by splitting the user input and used for method overloading by passing an int in one and a string in another. However I can do the sequential search by either ID and Name by using hashmap and making the key = name + ID and then doing key.contains(charSequence). Of course I used an array to split each element of the list. I read in a csv file into a linked list and then I split the linked list into sections based on category for each element. I just posted here to find the most efficient way to do this. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |