|
001 packagepackage is used to name the directory or folder a class is in intermediate;
002
003
004 /**
005 * This classclass is a group of fields and methods used for making objects is an implementation of a basic
006 * doubly-linked list of Strings that remains
007 * sorted.
008 * @authorthis is the Javadoc tag for documenting who created the source code Jam Jenkins
009 */
010 publicpublic is used to indicate unrestricted access (any other class can have access) classclass is a group of fields and methods used for making objects SortedLinkedList
011 {open braces start code blocks and must be matched with a close brace
012 /**
013 * This is an inner classclass is a group of fields and methods used for making objects that only has use
014 * within the SortedLinkedList. It holds a
015 * sequence of characters as its data and a
016 * pointer to the next and previous node. Users
017 * of the SortedLinkedList classclass is a group of fields and methods used for making objects should not ever
018 * need to see or use the Node classclass is a group of fields and methods used for making objects.
019 */
020 privateprivate is used to restrict access to the current class only classclass is a group of fields and methods used for making objects Node
021 {open braces start code blocks and must be matched with a close brace
022 String data;
023 Node next;
024 Node prev;
025
026 publicpublic is used to indicate unrestricted access (any other class can have access) Node(String data, Node prev, Node next)
027 {open braces start code blocks and must be matched with a close brace
028 thisthis means the current object (the implicit parameter).data=this assignment operator makes the left side equal to the right sidedata;
029 thisthis means the current object (the implicit parameter).next=this assignment operator makes the left side equal to the right sidenext;
030 thisthis means the current object (the implicit parameter).prev=this assignment operator makes the left side equal to the right sideprev;
031 }close braces end code blocks and must match an earlier open brace
032 }close braces end code blocks and must match an earlier open brace
033
034 /**where the list begins*/
035 privateprivate is used to restrict access to the current class only Node head;
036 /**where the list ends*/
037 privateprivate is used to restrict access to the current class only Node tail;
038
039 /**adds the data at the appropriate place in the sorted list
040 * @paramthis is the Javadoc tag for documenting the purpose of parameters data the information to add to the list
041 */
042 publicpublic is used to indicate unrestricted access (any other class can have access) voidvoid means the method does not return a value add(String data)
043 {open braces start code blocks and must be matched with a close brace
044 ifif executes the next statement only if the condition in parenthesis evaluates to true(head==this is the comparison operator which evaluates to true if both sides are the samenullnull is the value used to refer to a non-existant object)
045 {open braces start code blocks and must be matched with a close brace
046 Node node=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor Node(data, nullnull is the value used to refer to a non-existant object, nullnull is the value used to refer to a non-existant object);
047 head=this assignment operator makes the left side equal to the right sidenode;
048 tail=this assignment operator makes the left side equal to the right sidenode;
049 }close braces end code blocks and must match an earlier open brace
050 elseelse is what happens when the if condition is false
051 {open braces start code blocks and must be matched with a close brace
052 Node current=this assignment operator makes the left side equal to the right sidehead;
053 whilewhile is a looping structure for executing code repeatedly(data.compareTo(current.data)>0 &this performs a bit-wise and (not the same as boolean and which is &&)&this performs a bit-wise and (not the same as boolean and which is &&) current.next!=this is the not equals operator which evaluates to true if both sides are differentnullnull is the value used to refer to a non-existant object)
054 current=this assignment operator makes the left side equal to the right sidecurrent.next;
055 ifif executes the next statement only if the condition in parenthesis evaluates to true(data.compareTo(current.data)>0)
056 {open braces start code blocks and must be matched with a close brace
057 Node node=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor Node(data, tail, nullnull is the value used to refer to a non-existant object);
058 tail.next=this assignment operator makes the left side equal to the right sidenode;
059 tail=this assignment operator makes the left side equal to the right sidenode;
060 }close braces end code blocks and must match an earlier open brace
061 elseelse is what happens when the if condition is false ifif executes the next statement only if the condition in parenthesis evaluates to true(current.prev==this is the comparison operator which evaluates to true if both sides are the samenullnull is the value used to refer to a non-existant object)
062 {open braces start code blocks and must be matched with a close brace
063 Node node=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor Node(data, nullnull is the value used to refer to a non-existant object, head);
064 head.prev=this assignment operator makes the left side equal to the right sidenode;
065 head=this assignment operator makes the left side equal to the right sidenode;
066 }close braces end code blocks and must match an earlier open brace
067 elseelse is what happens when the if condition is false
068 {open braces start code blocks and must be matched with a close brace
069 Node node=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor Node(data, current.prev, current);
070 current.prev.next=this assignment operator makes the left side equal to the right sidenode;
071 current.prev=this assignment operator makes the left side equal to the right sidenode;
072 }close braces end code blocks and must match an earlier open brace
073 }close braces end code blocks and must match an earlier open brace
074 }close braces end code blocks and must match an earlier open brace
075
076 /**removes the element ifif executes the next statement only if the condition in parenthesis evaluates to true it exists, otherwise returns nullnull is the value used to refer to a non-existant object
077 * @paramthis is the Javadoc tag for documenting the purpose of parameters index which element to remove.
078 * @returnnull the String at the given position
079 * Zero indicates the first element and the valid indexes go
080 * up to one less than the number of elements
081 */
082 publicpublic is used to indicate unrestricted access (any other class can have access) String remove(intint is the type for whole numbers and it is short for integer index)
083 {open braces start code blocks and must be matched with a close brace
084 //add your implementation here
085 returnreturn means to provide the result of the method and/or cease execution of the method immediately nullnull is the value used to refer to a non-existant object;
086 }close braces end code blocks and must match an earlier open brace
087
088 /**gets the element ifif executes the next statement only if the condition in parenthesis evaluates to true it exists, otherwise returns nullnull is the value used to refer to a non-existant object
089 * @paramthis is the Javadoc tag for documenting the purpose of parameters index which element to returnreturn means to provide the result of the method and/or cease execution of the method immediately.
090 * Zero indicates the first element and the valid indexes go
091 * up to one less than the number of elements
092 */
093 publicpublic is used to indicate unrestricted access (any other class can have access) String get(intint is the type for whole numbers and it is short for integer index)
094 {open braces start code blocks and must be matched with a close brace
095 //add your implementation here
096 returnreturn means to provide the result of the method and/or cease execution of the method immediately nullnull is the value used to refer to a non-existant object;
097 }close braces end code blocks and must match an earlier open brace
098
099 /**merges the current linked list with the other linked list
100 * Note: thisthis means the current object (the implicit parameter) method changes the value of the parameter!this is the not operator, which changes true to false and false to true
101 * This and other are identical after thisthis means the current object (the implicit parameter) call. After calling
102 * thisthis means the current object (the implicit parameter) method, thisthis means the current object (the implicit parameter) and other have the same contents which is
103 * the union of the original contents, still ordered.
104 * @paramthis is the Javadoc tag for documenting the purpose of parameters other the list to merge with thisthis means the current object (the implicit parameter) one.
105 */
106 publicpublic is used to indicate unrestricted access (any other class can have access) voidvoid means the method does not return a value mergeTogether(SortedLinkedList other)
107 {open braces start code blocks and must be matched with a close brace
108 //add your implementation here
109 }close braces end code blocks and must match an earlier open brace
110
111 /**converts the list into a readable text version
112 * @returnnull the text version of the list
113 */
114 publicpublic is used to indicate unrestricted access (any other class can have access) String toString()
115 {open braces start code blocks and must be matched with a close brace
116 Node current=this assignment operator makes the left side equal to the right sidehead;
117 String total=this assignment operator makes the left side equal to the right side"head<->";
118 whilewhile is a looping structure for executing code repeatedly(current!=this is the not equals operator which evaluates to true if both sides are differentnullnull is the value used to refer to a non-existant object)
119 {open braces start code blocks and must be matched with a close brace
120 total+=this increases the variable on the left by the value on the rightcurrent.data+adds two numbers together or concatenates Strings together"<->";
121 current=this assignment operator makes the left side equal to the right sidecurrent.next;
122 }close braces end code blocks and must match an earlier open brace
123 total+=this increases the variable on the left by the value on the right"tail";
124 returnreturn means to provide the result of the method and/or cease execution of the method immediately total;
125 }close braces end code blocks and must match an earlier open brace
126
127 /**thisthis means the current object (the implicit parameter) performs tests of SortedLinkedList to make sure it
128 * works as specified
129 * @paramthis is the Javadoc tag for documenting the purpose of parameters args not used
130 */
131 publicpublic is used to indicate unrestricted access (any other class can have access) staticstatic means that an instance is not required for access (class level access) voidvoid means the method does not return a value mainThe main method is the place where applications begin executing.(String[brackets are typically used to declare, initialize and index (indicate which element of) arrays]brackets are typically used to declare, initialize and index (indicate which element of) arrays args)
132 {open braces start code blocks and must be matched with a close brace
133 SortedLinkedList list=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor SortedLinkedList();
134 list.add("Jam");
135 list.add("Jenkins");
136 list.add("Christopher");
137 System.out.println("list is "+adds two numbers together or concatenates Strings togetherlist);
138 }close braces end code blocks and must match an earlier open brace
139 }close braces end code blocks and must match an earlier open brace
|