Nice TWiki > Doc > ListsBeginnerExample (r1.1 vs. r1.5) TWiki webs:
Dev | Doc | Main | TWiki | Sandbox
Doc . { Changes | Index | Search | Go }
 <<O>>  Difference Topic ListsBeginnerExample (r1.5 - 10 Jan 2004 - IsaacGouy)
Changed:
<
<

ArrayList? L2 = L1.clone();

>
>

ArrayList? L2 = L1.clone;

Changed:
<
<

while (L2.size() > 0)

>
>

while (L2.size > 0)

Changed:
<
<

while ( (index = L3.size()) > 0)

>
>

while ( (index = L3.size) > 0)

Changed:
<
<

L1Count = L1.size();

>
>

L1Count = L1.size;


 <<O>>  Difference Topic ListsBeginnerExample (r1.4 - 10 Jan 2004 - IsaacGouy)
Changed:
<
<

*/

>
>

*/


 <<O>>  Difference Topic ListsBeginnerExample (r1.3 - 27 Aug 2003 - IsaacGouy)
Changed:
<
<

/* Please try the BeginnerExamples? before the NoviceExamples?

>
>

/* Please try the NoviceExamples? before the BeginnerExamples?

Added:
>
>

%META:TOPICMOVED{by="IsaacGouy" date="1062001758" from="Doc.ListsNoviceExample" to="Doc.ListsBeginnerExample"}%


 <<O>>  Difference Topic ListsBeginnerExample (r1.2 - 27 Aug 2003 - IsaacGouy)
Changed:
<
<

nicec --sourcepath=.. -d=. -a lists.jar lists

>
>

nicec --sourcepath=.. -a lists.jar lists


 <<O>>  Difference Topic ListsBeginnerExample (r1.1 - 27 Aug 2003 - IsaacGouy)
Added:
>
>

%META:TOPICINFO{author="IsaacGouy" date="1061942833" format="1.0" version="1.1"}% %META:TOPICPARENT{name="CodeExamples"}%

/* Please try the BeginnerExamples before the NoviceExamples
To compile:
   nicec --sourcepath=.. -d=. -a lists.jar lists
To run:
   java -jar lists.jar 16
*/


void main(String[] args){
   var n = toSingleInt(args);

   let nSize = 10000;
   int L1Count = 0;

   while (n-- > 0){
      // initialize L1
      ArrayList<int> L1 = new ArrayList(nSize);
      for (var j = 1; j <= nSize; j++) L1.add(j);

      // copy L1 to L2
      ArrayList<int> L2 = L1.clone();

      // remove from left of L2 add to right of L3
      ArrayList<int> L3 = new ArrayList(nSize);
      while (L2.size() > 0) 
         L3.add( L2.removeAt(0) ); 

      // remove from right of L3 add to right of L2
      int index;
      while ( (index = L3.size()) > 0) 
         L2.add( L3.removeAt(index - 1) );

      // reverse L1
      Collections.reverse(L1);

      // check that first item is now SIZE
      // NOTE: no Object to int type cast needed

      if (L1[0] != nSize) println("First item of L1 != SIZE");

      // check that L1 == L2
      if ( !L1.equals(L2) ) println("L1 != L2");
      L1Count = L1.size();
      }

   println(L1Count);
}


int toSingleInt(String[] s){
   try { return Integer.parseInt(s[0]); }
   catch (Exception e){ return 1; } }


/* Notes - language
Compare with Java at the "Win32 Language Shootout"

*/

-- IsaacGouy - 27 Aug 2003


Topic ListsBeginnerExample . { View | Diffs | r1.5 | > | r1.4 | > | r1.3 | More }
Revision r1.1 - 27 Aug 2003 - 00:07 GMT - IsaacGouy
Revision r1.5 - 10 Jan 2004 - 19:05 GMT - IsaacGouy
Copyright © 1999-2003 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding TWiki? Send feedback.