Browse Source

Fixed copy()

NedRedmond 6 years ago
parent
commit
27f143620c

+ 43
- 59
.idea/workspace.xml View File

2
 <project version="4">
2
 <project version="4">
3
   <component name="ChangeListManager">
3
   <component name="ChangeListManager">
4
     <list default="true" id="4cada9f2-6d0f-46eb-ad0f-05b3102352a5" name="Default Changelist" comment="">
4
     <list default="true" id="4cada9f2-6d0f-46eb-ad0f-05b3102352a5" name="Default Changelist" comment="">
5
-      <change beforePath="$PROJECT_DIR$/.idea/compiler.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/compiler.xml" afterDir="false" />
6
-      <change beforePath="$PROJECT_DIR$/.idea/misc.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/misc.xml" afterDir="false" />
7
-      <change beforePath="$PROJECT_DIR$/.idea/modules.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/modules.xml" afterDir="false" />
8
-      <change beforePath="$PROJECT_DIR$/.idea/vcs.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/vcs.xml" afterDir="false" />
9
       <change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
5
       <change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
10
-      <change beforePath="$PROJECT_DIR$/pom.xml" beforeDir="false" afterPath="$PROJECT_DIR$/pom.xml" afterDir="false" />
11
-      <change beforePath="$PROJECT_DIR$/src/main/java/com/zipcodewilmington/singlylinkedlist/MainApplication.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/java/com/zipcodewilmington/singlylinkedlist/MainApplication.java" afterDir="false" />
12
       <change beforePath="$PROJECT_DIR$/src/main/java/com/zipcodewilmington/singlylinkedlist/SinglyLinkedList.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/java/com/zipcodewilmington/singlylinkedlist/SinglyLinkedList.java" afterDir="false" />
6
       <change beforePath="$PROJECT_DIR$/src/main/java/com/zipcodewilmington/singlylinkedlist/SinglyLinkedList.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/java/com/zipcodewilmington/singlylinkedlist/SinglyLinkedList.java" afterDir="false" />
13
       <change beforePath="$PROJECT_DIR$/src/test/java/com/zipcodewilmington/singlylinkedlist/SinglyLinkedListTest.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/test/java/com/zipcodewilmington/singlylinkedlist/SinglyLinkedListTest.java" afterDir="false" />
7
       <change beforePath="$PROJECT_DIR$/src/test/java/com/zipcodewilmington/singlylinkedlist/SinglyLinkedListTest.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/test/java/com/zipcodewilmington/singlylinkedlist/SinglyLinkedListTest.java" afterDir="false" />
14
     </list>
8
     </list>
23
     <session id="-472648142">
17
     <session id="-472648142">
24
       <usages-collector id="statistics.lifecycle.project">
18
       <usages-collector id="statistics.lifecycle.project">
25
         <counts>
19
         <counts>
26
-          <entry key="project.closed" value="4" />
20
+          <entry key="project.closed" value="6" />
27
           <entry key="project.open.time.0" value="1" />
21
           <entry key="project.open.time.0" value="1" />
28
-          <entry key="project.open.time.1" value="2" />
22
+          <entry key="project.open.time.1" value="4" />
29
           <entry key="project.open.time.12" value="1" />
23
           <entry key="project.open.time.12" value="1" />
30
           <entry key="project.open.time.6" value="1" />
24
           <entry key="project.open.time.6" value="1" />
31
-          <entry key="project.opened" value="5" />
25
+          <entry key="project.opened" value="7" />
32
         </counts>
26
         </counts>
33
       </usages-collector>
27
       </usages-collector>
34
       <usages-collector id="statistics.file.extensions.open">
28
       <usages-collector id="statistics.file.extensions.open">
43
       </usages-collector>
37
       </usages-collector>
44
       <usages-collector id="statistics.file.extensions.edit">
38
       <usages-collector id="statistics.file.extensions.edit">
45
         <counts>
39
         <counts>
46
-          <entry key="java" value="3825" />
40
+          <entry key="java" value="4009" />
47
         </counts>
41
         </counts>
48
       </usages-collector>
42
       </usages-collector>
49
       <usages-collector id="statistics.file.types.edit">
43
       <usages-collector id="statistics.file.types.edit">
50
         <counts>
44
         <counts>
51
-          <entry key="JAVA" value="3825" />
45
+          <entry key="JAVA" value="4009" />
52
         </counts>
46
         </counts>
53
       </usages-collector>
47
       </usages-collector>
54
     </session>
48
     </session>
55
   </component>
49
   </component>
56
   <component name="FileEditorManager">
50
   <component name="FileEditorManager">
57
-    <splitter split-orientation="horizontal" split-proportion="0.43593314">
51
+    <splitter split-orientation="horizontal" split-proportion="0.45851216">
58
       <split-first>
52
       <split-first>
59
         <leaf SIDE_TABS_SIZE_LIMIT_KEY="300">
53
         <leaf SIDE_TABS_SIZE_LIMIT_KEY="300">
60
           <file pinned="false" current-in-tab="false">
54
           <file pinned="false" current-in-tab="false">
69
           <file pinned="false" current-in-tab="true">
63
           <file pinned="false" current-in-tab="true">
70
             <entry file="file://$PROJECT_DIR$/src/main/java/com/zipcodewilmington/singlylinkedlist/SinglyLinkedList.java">
64
             <entry file="file://$PROJECT_DIR$/src/main/java/com/zipcodewilmington/singlylinkedlist/SinglyLinkedList.java">
71
               <provider selected="true" editor-type-id="text-editor">
65
               <provider selected="true" editor-type-id="text-editor">
72
-                <state relative-caret-position="2235">
73
-                  <caret line="149" selection-start-line="149" selection-end-line="149" />
74
-                  <folding>
75
-                    <element signature="e#3864#3865#0" expanded="true" />
76
-                    <element signature="e#3896#3897#0" expanded="true" />
77
-                    <element signature="e#4115#4116#0" expanded="true" />
78
-                    <element signature="e#4155#4156#0" expanded="true" />
79
-                  </folding>
66
+                <state relative-caret-position="245">
67
+                  <caret line="124" column="29" lean-forward="true" selection-start-line="124" selection-start-column="29" selection-end-line="124" selection-end-column="35" />
80
                 </state>
68
                 </state>
81
               </provider>
69
               </provider>
82
             </entry>
70
             </entry>
93
           <file pinned="false" current-in-tab="false">
81
           <file pinned="false" current-in-tab="false">
94
             <entry file="file://$PROJECT_DIR$/src/test/java/com/zipcodewilmington/singlylinkedlist/SinglyLinkedListTest.java">
82
             <entry file="file://$PROJECT_DIR$/src/test/java/com/zipcodewilmington/singlylinkedlist/SinglyLinkedListTest.java">
95
               <provider selected="true" editor-type-id="text-editor">
83
               <provider selected="true" editor-type-id="text-editor">
96
-                <state relative-caret-position="165">
97
-                  <caret line="13" column="8" selection-start-line="13" selection-start-column="8" selection-end-line="13" selection-end-column="8" />
84
+                <state relative-caret-position="180">
85
+                  <caret line="12" column="8" selection-start-line="12" selection-start-column="8" selection-end-line="12" selection-end-column="8" />
98
                   <folding>
86
                   <folding>
99
                     <element signature="imports" expanded="true" />
87
                     <element signature="imports" expanded="true" />
100
                   </folding>
88
                   </folding>
109
           <file pinned="false" current-in-tab="true">
97
           <file pinned="false" current-in-tab="true">
110
             <entry file="file://$PROJECT_DIR$/src/test/java/com/zipcodewilmington/singlylinkedlist/SinglyLinkedListTest.java">
98
             <entry file="file://$PROJECT_DIR$/src/test/java/com/zipcodewilmington/singlylinkedlist/SinglyLinkedListTest.java">
111
               <provider selected="true" editor-type-id="text-editor">
99
               <provider selected="true" editor-type-id="text-editor">
112
-                <state relative-caret-position="299">
113
-                  <caret line="21" column="22" selection-start-line="21" selection-start-column="22" selection-end-line="21" selection-end-column="22" />
100
+                <state relative-caret-position="269">
101
+                  <caret line="193" column="9" lean-forward="true" selection-start-line="193" selection-start-column="9" selection-end-line="193" selection-end-column="9" />
114
                   <folding>
102
                   <folding>
115
                     <element signature="imports" expanded="true" />
103
                     <element signature="imports" expanded="true" />
116
                   </folding>
104
                   </folding>
121
           <file pinned="false" current-in-tab="false">
109
           <file pinned="false" current-in-tab="false">
122
             <entry file="jar:///Library/Java/JavaVirtualMachines/jdk1.8.0_191.jdk/Contents/Home/src.zip!/java/lang/Comparable.java">
110
             <entry file="jar:///Library/Java/JavaVirtualMachines/jdk1.8.0_191.jdk/Contents/Home/src.zip!/java/lang/Comparable.java">
123
               <provider selected="true" editor-type-id="text-editor">
111
               <provider selected="true" editor-type-id="text-editor">
124
-                <state relative-caret-position="-216">
112
+                <state relative-caret-position="1080">
125
                   <caret line="95" column="17" selection-start-line="95" selection-start-column="17" selection-end-line="95" selection-end-column="17" />
113
                   <caret line="95" column="17" selection-start-line="95" selection-start-column="17" selection-end-line="95" selection-end-column="17" />
126
                 </state>
114
                 </state>
127
               </provider>
115
               </provider>
231
   <component name="PropertiesComponent">
219
   <component name="PropertiesComponent">
232
     <property name="WebServerToolWindowFactoryState" value="false" />
220
     <property name="WebServerToolWindowFactoryState" value="false" />
233
     <property name="aspect.path.notification.shown" value="true" />
221
     <property name="aspect.path.notification.shown" value="true" />
234
-    <property name="com.android.tools.idea.instantapp.provision.ProvisionBeforeRunTaskProvider.myTimeStamp" value="1541259452760" />
222
+    <property name="com.android.tools.idea.instantapp.provision.ProvisionBeforeRunTaskProvider.myTimeStamp" value="1541262400955" />
235
     <property name="nodejs_interpreter_path.stuck_in_default_project" value="undefined stuck path" />
223
     <property name="nodejs_interpreter_path.stuck_in_default_project" value="undefined stuck path" />
236
     <property name="nodejs_npm_path_reset_for_default_project" value="true" />
224
     <property name="nodejs_npm_path_reset_for_default_project" value="true" />
237
   </component>
225
   </component>
247
       </list>
235
       </list>
248
     </option>
236
     </option>
249
   </component>
237
   </component>
250
-  <component name="RunManager" selected="JUnit.SinglyLinkedListTest">
238
+  <component name="RunManager" selected="JUnit.SinglyLinkedListTest.SinglyLinkedListTest11">
251
     <configuration name="SinglyLinkedListTest" type="JUnit" factoryName="JUnit" temporary="true" nameIsGenerated="true">
239
     <configuration name="SinglyLinkedListTest" type="JUnit" factoryName="JUnit" temporary="true" nameIsGenerated="true">
252
       <module name="singlylinkedlist" />
240
       <module name="singlylinkedlist" />
253
       <extension name="coverage">
241
       <extension name="coverage">
335
     </list>
323
     </list>
336
     <recent_temporary>
324
     <recent_temporary>
337
       <list>
325
       <list>
326
+        <item itemvalue="JUnit.SinglyLinkedListTest.SinglyLinkedListTest11" />
338
         <item itemvalue="JUnit.SinglyLinkedListTest" />
327
         <item itemvalue="JUnit.SinglyLinkedListTest" />
339
         <item itemvalue="JUnit.SinglyLinkedListTest.SinglyLinkedListTest12" />
328
         <item itemvalue="JUnit.SinglyLinkedListTest.SinglyLinkedListTest12" />
340
-        <item itemvalue="JUnit.SinglyLinkedListTest.SinglyLinkedListTest11" />
341
         <item itemvalue="JUnit.SinglyLinkedListTest.SinglyLinkedListTest10" />
329
         <item itemvalue="JUnit.SinglyLinkedListTest.SinglyLinkedListTest10" />
342
         <item itemvalue="JUnit.SinglyLinkedListTest.SinglyLinkedListTest9" />
330
         <item itemvalue="JUnit.SinglyLinkedListTest.SinglyLinkedListTest9" />
343
       </list>
331
       </list>
357
       <workItem from="1541027519485" duration="36000" />
345
       <workItem from="1541027519485" duration="36000" />
358
       <workItem from="1541092107678" duration="2198000" />
346
       <workItem from="1541092107678" duration="2198000" />
359
       <workItem from="1541196317502" duration="5339000" />
347
       <workItem from="1541196317502" duration="5339000" />
360
-      <workItem from="1541234299179" duration="5970000" />
348
+      <workItem from="1541234299179" duration="6045000" />
349
+      <workItem from="1541259898121" duration="48000" />
350
+      <workItem from="1541261768122" duration="1211000" />
361
     </task>
351
     </task>
362
     <servers />
352
     <servers />
363
   </component>
353
   </component>
364
   <component name="TestHistory">
354
   <component name="TestHistory">
365
-    <history-entry file="SinglyLinkedListTest_SinglyLinkedListTest12 - 2018.11.03 at 11h 14m 18s.xml">
366
-      <configuration name="SinglyLinkedListTest.SinglyLinkedListTest12" configurationId="JUnit" />
367
-    </history-entry>
368
-    <history-entry file="SinglyLinkedListTest_SinglyLinkedListTest12 - 2018.11.03 at 11h 18m 27s.xml">
369
-      <configuration name="SinglyLinkedListTest.SinglyLinkedListTest12" configurationId="JUnit" />
370
-    </history-entry>
371
-    <history-entry file="SinglyLinkedListTest_SinglyLinkedListTest12 - 2018.11.03 at 11h 19m 59s.xml">
372
-      <configuration name="SinglyLinkedListTest.SinglyLinkedListTest12" configurationId="JUnit" />
373
-    </history-entry>
374
-    <history-entry file="SinglyLinkedListTest_SinglyLinkedListTest12 - 2018.11.03 at 11h 20m 43s.xml">
375
-      <configuration name="SinglyLinkedListTest.SinglyLinkedListTest12" configurationId="JUnit" />
376
-    </history-entry>
377
-    <history-entry file="SinglyLinkedListTest_SinglyLinkedListTest12 - 2018.11.03 at 11h 20m 55s.xml">
378
-      <configuration name="SinglyLinkedListTest.SinglyLinkedListTest12" configurationId="JUnit" />
379
-    </history-entry>
380
-    <history-entry file="SinglyLinkedListTest - 2018.11.03 at 11h 28m 21s.xml">
381
-      <configuration name="SinglyLinkedListTest" configurationId="JUnit" />
382
-    </history-entry>
383
     <history-entry file="SinglyLinkedListTest - 2018.11.03 at 11h 28m 39s.xml">
355
     <history-entry file="SinglyLinkedListTest - 2018.11.03 at 11h 28m 39s.xml">
384
       <configuration name="SinglyLinkedListTest" configurationId="JUnit" />
356
       <configuration name="SinglyLinkedListTest" configurationId="JUnit" />
385
     </history-entry>
357
     </history-entry>
392
     <history-entry file="SinglyLinkedListTest - 2018.11.03 at 11h 29m 51s.xml">
364
     <history-entry file="SinglyLinkedListTest - 2018.11.03 at 11h 29m 51s.xml">
393
       <configuration name="SinglyLinkedListTest" configurationId="JUnit" />
365
       <configuration name="SinglyLinkedListTest" configurationId="JUnit" />
394
     </history-entry>
366
     </history-entry>
367
+    <history-entry file="SinglyLinkedListTest_SinglyLinkedListTest11 - 2018.11.03 at 12h 21m 35s.xml">
368
+      <configuration name="SinglyLinkedListTest.SinglyLinkedListTest11" configurationId="JUnit" />
369
+    </history-entry>
370
+    <history-entry file="SinglyLinkedListTest_SinglyLinkedListTest11 - 2018.11.03 at 12h 23m 01s.xml">
371
+      <configuration name="SinglyLinkedListTest.SinglyLinkedListTest11" configurationId="JUnit" />
372
+    </history-entry>
373
+    <history-entry file="SinglyLinkedListTest_SinglyLinkedListTest11 - 2018.11.03 at 12h 23m 30s.xml">
374
+      <configuration name="SinglyLinkedListTest.SinglyLinkedListTest11" configurationId="JUnit" />
375
+    </history-entry>
376
+    <history-entry file="SinglyLinkedListTest_SinglyLinkedListTest11 - 2018.11.03 at 12h 24m 06s.xml">
377
+      <configuration name="SinglyLinkedListTest.SinglyLinkedListTest11" configurationId="JUnit" />
378
+    </history-entry>
379
+    <history-entry file="SinglyLinkedListTest_SinglyLinkedListTest11 - 2018.11.03 at 12h 24m 28s.xml">
380
+      <configuration name="SinglyLinkedListTest.SinglyLinkedListTest11" configurationId="JUnit" />
381
+    </history-entry>
382
+    <history-entry file="SinglyLinkedListTest_SinglyLinkedListTest11 - 2018.11.03 at 12h 24m 56s.xml">
383
+      <configuration name="SinglyLinkedListTest.SinglyLinkedListTest11" configurationId="JUnit" />
384
+    </history-entry>
395
   </component>
385
   </component>
396
   <component name="TimeTrackingManager">
386
   <component name="TimeTrackingManager">
397
-    <option name="totallyTimeSpent" value="15139000" />
387
+    <option name="totallyTimeSpent" value="16473000" />
398
   </component>
388
   </component>
399
   <component name="ToolWindowManager">
389
   <component name="ToolWindowManager">
400
     <frame x="0" y="0" width="1440" height="900" extended-state="6" />
390
     <frame x="0" y="0" width="1440" height="900" extended-state="6" />
454
     </entry>
444
     </entry>
455
     <entry file="jar:///Library/Java/JavaVirtualMachines/jdk1.8.0_191.jdk/Contents/Home/src.zip!/java/lang/Comparable.java">
445
     <entry file="jar:///Library/Java/JavaVirtualMachines/jdk1.8.0_191.jdk/Contents/Home/src.zip!/java/lang/Comparable.java">
456
       <provider selected="true" editor-type-id="text-editor">
446
       <provider selected="true" editor-type-id="text-editor">
457
-        <state relative-caret-position="-216">
447
+        <state relative-caret-position="1080">
458
           <caret line="95" column="17" selection-start-line="95" selection-start-column="17" selection-end-line="95" selection-end-column="17" />
448
           <caret line="95" column="17" selection-start-line="95" selection-start-column="17" selection-end-line="95" selection-end-column="17" />
459
         </state>
449
         </state>
460
       </provider>
450
       </provider>
461
     </entry>
451
     </entry>
462
     <entry file="file://$PROJECT_DIR$/src/main/java/com/zipcodewilmington/singlylinkedlist/SinglyLinkedList.java">
452
     <entry file="file://$PROJECT_DIR$/src/main/java/com/zipcodewilmington/singlylinkedlist/SinglyLinkedList.java">
463
       <provider selected="true" editor-type-id="text-editor">
453
       <provider selected="true" editor-type-id="text-editor">
464
-        <state relative-caret-position="2235">
465
-          <caret line="149" selection-start-line="149" selection-end-line="149" />
466
-          <folding>
467
-            <element signature="e#3864#3865#0" expanded="true" />
468
-            <element signature="e#3896#3897#0" expanded="true" />
469
-            <element signature="e#4115#4116#0" expanded="true" />
470
-            <element signature="e#4155#4156#0" expanded="true" />
471
-          </folding>
454
+        <state relative-caret-position="245">
455
+          <caret line="124" column="29" lean-forward="true" selection-start-line="124" selection-start-column="29" selection-end-line="124" selection-end-column="35" />
472
         </state>
456
         </state>
473
       </provider>
457
       </provider>
474
     </entry>
458
     </entry>
475
     <entry file="file://$PROJECT_DIR$/src/test/java/com/zipcodewilmington/singlylinkedlist/SinglyLinkedListTest.java">
459
     <entry file="file://$PROJECT_DIR$/src/test/java/com/zipcodewilmington/singlylinkedlist/SinglyLinkedListTest.java">
476
       <provider selected="true" editor-type-id="text-editor">
460
       <provider selected="true" editor-type-id="text-editor">
477
-        <state relative-caret-position="299">
478
-          <caret line="21" column="22" selection-start-line="21" selection-start-column="22" selection-end-line="21" selection-end-column="22" />
461
+        <state relative-caret-position="269">
462
+          <caret line="193" column="9" lean-forward="true" selection-start-line="193" selection-start-column="9" selection-end-line="193" selection-end-column="9" />
479
           <folding>
463
           <folding>
480
             <element signature="imports" expanded="true" />
464
             <element signature="imports" expanded="true" />
481
           </folding>
465
           </folding>

+ 13
- 4
src/main/java/com/zipcodewilmington/singlylinkedlist/SinglyLinkedList.java View File

117
         return false;
117
         return false;
118
     }
118
     }
119
 
119
 
120
-    public SinglyLinkedList<T> copy(SinglyLinkedList<T> original) {
121
-        SinglyLinkedList<T> copyOfOriginal = new SinglyLinkedList<T>();
122
-        copyOfOriginal = original;
123
-        return copyOfOriginal;
120
+    public SinglyLinkedList<T> copy() {
121
+        SinglyLinkedList<T> copy = new SinglyLinkedList<T>();
122
+
123
+        Node node = head;
124
+
125
+        for (int i = 1; i <= size() && node.getNext() != null; i++) {
126
+            copy.add(node.getData());
127
+            node = node.getNext();
128
+        }
129
+
130
+        copy.add(tail.getData());
131
+
132
+        return copy;
124
     }
133
     }
125
 
134
 
126
     public void sort() {
135
     public void sort() {

+ 15
- 3
src/test/java/com/zipcodewilmington/singlylinkedlist/SinglyLinkedListTest.java View File

1
 package com.zipcodewilmington.singlylinkedlist;
1
 package com.zipcodewilmington.singlylinkedlist;
2
 
2
 
3
 import org.junit.Assert;
3
 import org.junit.Assert;
4
-import org.junit.Before;
5
 import org.junit.Test;
4
 import org.junit.Test;
6
 
5
 
7
 /**
6
 /**
182
         linkedList.add("c");
181
         linkedList.add("c");
183
 
182
 
184
         SinglyLinkedList actual = linkedList;
183
         SinglyLinkedList actual = linkedList;
185
-        SinglyLinkedList expected = linkedList.copy(linkedList);
184
+        SinglyLinkedList expected = linkedList.copy();
185
+
186
+        for (int i = 1; i <= expected.size(); i++) {
187
+            System.out.println(expected.get(i));
188
+        }
189
+
190
+        expected.remove();
191
+
192
+        for (int i = 1; i <= expected.size(); i++) {
193
+            System.out.println(expected.get(i));
194
+        }
195
+
196
+        for (int i = 1; i < linkedList.size()+1; i++) {
197
+            System.out.println(linkedList.get(i));
198
+        }
186
 
199
 
187
-        Assert.assertTrue(actual.equals(expected));
188
     }
200
     }
189
 
201
 
190
     @Test
202
     @Test