java - Trying to sort string given with respective order, cannot use collection -
I'm having trouble sorting the string in my linked link, numbers can be easily compared to each other and They descend ascending order or descending.
Public square nodes {Private size size; Private node nextNode; Private node PreviousNode; Private Boolean Front = Wrong; Node () {this.shape = null; This.nextNode = Null; This.previousNode = null; } Public node (size size, node active) {this.shape = shape; This.nextNode = Null; This.previousNode = null; } Public node addNode (size size) getShape (set size) getNextNode () setNextNode (node nextNode) getPreviousNode () setPreviousNode (node previousNode) Public Boolean front () Public Zero setFront (Boolean front)} / Pre> This should be like (square, rectangle, circle, oval, line)
public class linkedlist {node front node end public linkedlist () {this. SetFront (zero); This.end = null; } Public Zero addFront (size size) Public Zero addNewNode (size size) Public Boolean AscendingOrder (node current) {node compareNextNode = current.getNextNode (); While (compareNextNode.equals (zero)) {if (current.getShape (TypeOfShape == "class".) {Node PreviousCurrent = current.getNextNode (); Then I do not know how to make algorithms to solve the rest of the size, if there is any good reference to anyone who can help me, then I would be happy
I would recommend doing this:
- Change your
sizeCreate square toolcomparable & lt; Size & gt; -
defined last fixed String [] shapeOrder; ..array that defines the order of the shape - Implement the
comparemethod using this previous array: firstsize orderGet the current shape index based on the array andTypeOfShape. After getting the index to compare both the current object and the object, compare the index, the less index will be smaller , the larger index the major (its use of this behavior Will depend on). - In your sorting algorithm, when comparing, simply
current.getShape (). CompareTo (otherNode.getShape ()),If you want to make both ascending and descending order, then apply two classes which are
comparativeInstead, with a similar comparison logic as described above.
Comments
Post a Comment