From ggc
|
001 packagepackage is used to name the directory or folder a class is in intermediate;
002
003 importimport means to make the classes and/or packages available in this program wiki.Wiki;
004
005 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 FunList
006 {open braces start code blocks and must be matched with a close brace
007 classclass is a group of fields and methods used for making objects Node
008 {open braces start code blocks and must be matched with a close brace
009 Object data;
010 Node next;
011 }close braces end code blocks and must match an earlier open brace
012
013 privateprivate is used to restrict access to the current class only Node first;
014
015 publicpublic is used to indicate unrestricted access (any other class can have access) voidvoid means the method does not return a value addFirst(Object object)
016 {open braces start code blocks and must be matched with a close brace
017 Node node=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor Node();
018 node.data=this assignment operator makes the left side equal to the right sideobject;
019 node.next=this assignment operator makes the left side equal to the right sidefirst;
020 first=this assignment operator makes the left side equal to the right sidenode;
021 }close braces end code blocks and must match an earlier open brace
022
023 publicpublic is used to indicate unrestricted access (any other class can have access) Object removeFirst()
024 {open braces start code blocks and must be matched with a close brace
025
026 ifif executes the next statement only if the condition in parenthesis evaluates to true(first==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)
027 {open braces start code blocks and must be matched with a close brace
028 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;
029 }close braces end code blocks and must match an earlier open brace
030 elseelse is what happens when the if condition is false
031 {open braces start code blocks and must be matched with a close brace
032 Object result=this assignment operator makes the left side equal to the right sidefirst.data;
033 first=this assignment operator makes the left side equal to the right sidefirst.next;
034 returnreturn means to provide the result of the method and/or cease execution of the method immediately result;
035 }close braces end code blocks and must match an earlier open brace
036 }close braces end code blocks and must match an earlier open brace
037
038 publicpublic is used to indicate unrestricted access (any other class can have access) voidvoid means the method does not return a value addLast(Object object)
039 {open braces start code blocks and must be matched with a close brace
040 ifif executes the next statement only if the condition in parenthesis evaluates to true(first==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)
041 {open braces start code blocks and must be matched with a close brace
042 addFirst(object);
043 }close braces end code blocks and must match an earlier open brace
044 elseelse is what happens when the if condition is false
045 {open braces start code blocks and must be matched with a close brace
046 Node current=this assignment operator makes the left side equal to the right sidefirst;
047 whilewhile is a looping structure for executing code repeatedly(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)
048 {open braces start code blocks and must be matched with a close brace
049 current=this assignment operator makes the left side equal to the right sidecurrent.next;
050 }close braces end code blocks and must match an earlier open brace
051 Node toAdd=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor Node();
052 toAdd.data=this assignment operator makes the left side equal to the right sideobject;
053 toAdd.next=this assignment operator makes the left side equal to the right sidenullnull is the value used to refer to a non-existant object;
054 current.next=this assignment operator makes the left side equal to the right sidetoAdd;
055 }close braces end code blocks and must match an earlier open brace
056 }close braces end code blocks and must match an earlier open brace
057
058 /**
059 * adds the object toAdd after the target. In the
060 * event the target does not exist, adds to the end
061 * of the list.
062 * @paramthis is the Javadoc tag for documenting the purpose of parameters target to object to look forfor is a looping structure for repeatedly executing a block of code
063 * @paramthis is the Javadoc tag for documenting the purpose of parameters toAdd the object to add after target
064 */
065 publicpublic is used to indicate unrestricted access (any other class can have access) voidvoid means the method does not return a value addAfter(Object target, Object toAdd)
066 {open braces start code blocks and must be matched with a close brace}close braces end code blocks and must match an earlier open brace
067
068 /**
069 * adds the object toAdd before the target. In the
070 * event the target does not exist, adds to the beginning
071 * of the list.
072 * @paramthis is the Javadoc tag for documenting the purpose of parameters target to object to look forfor is a looping structure for repeatedly executing a block of code
073 * @paramthis is the Javadoc tag for documenting the purpose of parameters toAdd the object to add before target
074 */
075 publicpublic is used to indicate unrestricted access (any other class can have access) voidvoid means the method does not return a value addBefore(Object target, Object toAdd)
076 {open braces start code blocks and must be matched with a close brace}close braces end code blocks and must match an earlier open brace
077
078 publicpublic is used to indicate unrestricted access (any other class can have access) Object removeLast(Object object)
079 {open braces start code blocks and must be matched with a close brace
080 ifif executes the next statement only if the condition in parenthesis evaluates to true(first==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)
081 {open braces start code blocks and must be matched with a close brace
082 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;
083 }close braces end code blocks and must match an earlier open brace
084 elseelse is what happens when the if condition is false ifif executes the next statement only if the condition in parenthesis evaluates to true(first.next==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)
085 {open braces start code blocks and must be matched with a close brace
086 returnreturn means to provide the result of the method and/or cease execution of the method immediately removeFirst();
087 }close braces end code blocks and must match an earlier open brace
088 elseelse is what happens when the if condition is false
089 {open braces start code blocks and must be matched with a close brace
090 Node current=this assignment operator makes the left side equal to the right sidefirst;
091 whilewhile is a looping structure for executing code repeatedly(current.next.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)
092 {open braces start code blocks and must be matched with a close brace
093 current=this assignment operator makes the left side equal to the right sidecurrent.next;
094 }close braces end code blocks and must match an earlier open brace
095 Object result=this assignment operator makes the left side equal to the right sidecurrent.next.data;
096 current.next=this assignment operator makes the left side equal to the right sidenullnull is the value used to refer to a non-existant object;
097 returnreturn means to provide the result of the method and/or cease execution of the method immediately result;
098 }close braces end code blocks and must match an earlier open brace
099 }close braces end code blocks and must match an earlier open brace
100
101 publicpublic is used to indicate unrestricted access (any other class can have access) String toString()
102 {open braces start code blocks and must be matched with a close brace
103 String total=this assignment operator makes the left side equal to the right side"";
104 Node current=this assignment operator makes the left side equal to the right sidefirst;
105 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)
106 {open braces start code blocks and must be matched with a close brace
107 total+=this increases the variable on the left by the value on the rightcurrent.data.toString()+adds two numbers together or concatenates Strings together"->";
108 current=this assignment operator makes the left side equal to the right sidecurrent.next;
109 }close braces end code blocks and must match an earlier open brace
110 returnreturn means to provide the result of the method and/or cease execution of the method immediately total;
111 }close braces end code blocks and must match an earlier open brace
112
113 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)
114 {open braces start code blocks and must be matched with a close brace
115 FunList list=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor FunList();
116 list.addFirst("Hello");
117 list.addFirst("List");
118 //list.removeFirst();
119 //list.removeFirst();
120 //list.removeFirst();
121 Wiki.out.println(list);
122 }close braces end code blocks and must match an earlier open brace
123 }close braces end code blocks and must match an earlier open brace
|
Download/View intermediate/FunList.java