<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en-GB">
	<id>https://wiki.kram.nz/index.php?action=history&amp;feed=atom&amp;title=SE250%3Alab-3%3Ajham005%3Alab-3.c</id>
	<title>SE250:lab-3:jham005:lab-3.c - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.kram.nz/index.php?action=history&amp;feed=atom&amp;title=SE250%3Alab-3%3Ajham005%3Alab-3.c"/>
	<link rel="alternate" type="text/html" href="https://wiki.kram.nz/index.php?title=SE250:lab-3:jham005:lab-3.c&amp;action=history"/>
	<updated>2026-09-25T20:13:18Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.46.0</generator>
	<entry>
		<id>https://wiki.kram.nz/index.php?title=SE250:lab-3:jham005:lab-3.c&amp;diff=5558&amp;oldid=prev</id>
		<title>Mark: 1 revision(s)</title>
		<link rel="alternate" type="text/html" href="https://wiki.kram.nz/index.php?title=SE250:lab-3:jham005:lab-3.c&amp;diff=5558&amp;oldid=prev"/>
		<updated>2008-11-03T05:19:20Z</updated>

		<summary type="html">&lt;p&gt;1 revision(s)&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt; /*&lt;br /&gt;
   File:   lab-3.c&lt;br /&gt;
   Date:   18 March 2008&lt;br /&gt;
   Author: John Hamer&lt;br /&gt;
   Purpose: Sample solution to SOFTENG 250 lab #3&lt;br /&gt;
 &lt;br /&gt;
   The code uses a modified version of arraylist.c that allows the&lt;br /&gt;
   ArrayList growth strategy to be customised by setting three&lt;br /&gt;
   parameters:&lt;br /&gt;
     ARRAYLIST_GROWTH_FACTOR&lt;br /&gt;
     ARRAYLIST_MIN_ALLOC&lt;br /&gt;
     ARRAYLIST_GROWTH_INCR&lt;br /&gt;
 &lt;br /&gt;
   The output is a script for the statistical package R.&lt;br /&gt;
 */&lt;br /&gt;
 &lt;br /&gt;
 #include &amp;lt;stdio.h&amp;gt;&lt;br /&gt;
 #include &amp;lt;time.h&amp;gt;&lt;br /&gt;
 #include &amp;lt;math.h&amp;gt;&lt;br /&gt;
 #include &amp;quot;arraylist.h&amp;quot;&lt;br /&gt;
 &lt;br /&gt;
 /* Set R_EOF to C-z for R running on Windows, or C-d for R running on Unix */&lt;br /&gt;
 char R_EOF = &amp;#039;Z&amp;#039; - &amp;#039;A&amp;#039; + 1;&lt;br /&gt;
 &lt;br /&gt;
 &lt;br /&gt;
 /* Don&amp;#039;t attempt further experiments after one takes over 5 seconds */&lt;br /&gt;
 int MAX_DELAY = CLOCKS_PER_SEC * 5;&lt;br /&gt;
 &lt;br /&gt;
 char INSERT_BACK[]  = &amp;quot;back&amp;quot;;&lt;br /&gt;
 char INSERT_FRONT[] = &amp;quot;front&amp;quot;;&lt;br /&gt;
 &lt;br /&gt;
 void Rplot( int plot, int* times, double gfactor, int incr, int minalloc, char* pos, char* colour, char pch ) {&lt;br /&gt;
   int t;&lt;br /&gt;
 &lt;br /&gt;
   ARRAYLIST_GROWTH_FACTOR = gfactor;&lt;br /&gt;
   ARRAYLIST_MIN_ALLOC     = minalloc;&lt;br /&gt;
   ARRAYLIST_GROWTH_INCR   = incr;&lt;br /&gt;
 &lt;br /&gt;
   printf( &amp;quot;leg.txt = c(leg.txt, \&amp;quot;%3.1f+%d[%d], %s\&amp;quot;)\n&amp;quot;, gfactor, incr, minalloc, pos );&lt;br /&gt;
   printf( &amp;quot;leg.pch = c(leg.pch, %d)\n&amp;quot;, (int)pch );&lt;br /&gt;
   printf( &amp;quot;leg.col = c(leg.col, %s)\n&amp;quot;, colour );&lt;br /&gt;
   printf( &amp;quot;data &amp;lt;- read.table( stdin( ) )\n&amp;quot; );&lt;br /&gt;
 &lt;br /&gt;
   for( t = 0; times[ t ] != 0; t++ ) {&lt;br /&gt;
     ArrayList xs;&lt;br /&gt;
     long i;&lt;br /&gt;
     clock_t t0, diff;&lt;br /&gt;
 &lt;br /&gt;
     arraylist_init( &amp;amp;xs );&lt;br /&gt;
 &lt;br /&gt;
     if( gfactor == infinity( ) )&lt;br /&gt;
       ensure_capacity( &amp;amp;xs, times[ t ] );&lt;br /&gt;
 &lt;br /&gt;
     t0 = clock( );&lt;br /&gt;
     if( pos == INSERT_BACK )&lt;br /&gt;
       for( i = 0; i &amp;lt; times[ t ]; i++ )&lt;br /&gt;
 	arraylist_push( &amp;amp;xs, 0 );&lt;br /&gt;
     else&lt;br /&gt;
       for( i = 0; i &amp;lt; times[ t ]; i++ )&lt;br /&gt;
 	arraylist_put( &amp;amp;xs, 0, 0 );&lt;br /&gt;
 &lt;br /&gt;
     diff = clock( ) - t0;&lt;br /&gt;
     printf( &amp;quot;%d %ld\n&amp;quot;, times[ t ]/1000, diff );&lt;br /&gt;
 &lt;br /&gt;
     arraylist_clear( &amp;amp;xs );&lt;br /&gt;
 &lt;br /&gt;
     if( diff &amp;gt; MAX_DELAY )&lt;br /&gt;
       break;&lt;br /&gt;
   }&lt;br /&gt;
   printf( &amp;quot;%c\n&amp;quot;, R_EOF );&lt;br /&gt;
   if( plot == 0 )&lt;br /&gt;
     /* The first plot determines the limits of the time axis */&lt;br /&gt;
     printf( &amp;quot;\nplot( data, type=\&amp;quot;o\&amp;quot;, pch=%d, col=%s, xlab=\&amp;quot;Elements added (000s)\&amp;quot;, ylab=\&amp;quot;Time (/1000s)\&amp;quot; )\n&amp;quot;, pch, colour );&lt;br /&gt;
   else&lt;br /&gt;
     printf( &amp;quot;\npoints( data, type=\&amp;quot;o\&amp;quot;, pch=%d, col=%s )\n&amp;quot;, pch, colour );&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 &lt;br /&gt;
 int main( ) {&lt;br /&gt;
   double gf[] = { 1.1, 1.2, 1.3, 1.4, 1.5, 2.0, 2.5, 3.0, 4.0, infinity( ), 0 };&lt;br /&gt;
   int times[] = { 100, 1000, 2000, 5000, 10000, 100000, 1000000, 2000000, 4000000, 8000000, 0 };&lt;br /&gt;
   //int times[] = { 10000, 12000, 14000, 16000, 18000, 20000, 25000, 30000, 40000, 50000, 0 };&lt;br /&gt;
   //double gf[] = { 0 };&lt;br /&gt;
   int g;&lt;br /&gt;
 &lt;br /&gt;
   ARRAYLIST_ALWAYS_MALLOC = 1;	/* see comments in arraylist.c:ensure_capacity */&lt;br /&gt;
 &lt;br /&gt;
   printf( &amp;quot;leg.txt = c()\nleg.pch = c()\nleg.col = c()\n&amp;quot; );&lt;br /&gt;
   for( g = 0; gf[ g ] != 0; g++ )&lt;br /&gt;
     Rplot( g, times, gf[ g ], 0, 16, INSERT_BACK, &amp;quot;\&amp;quot;black\&amp;quot;&amp;quot;, &amp;#039;a&amp;#039; + g );&lt;br /&gt;
   printf( &amp;quot;misc.cols=rainbow(4)\n&amp;quot; );&lt;br /&gt;
   Rplot( g++, times, 2.0, 0,    16,   INSERT_FRONT, &amp;quot;misc.cols[1]&amp;quot;, 22 );&lt;br /&gt;
   Rplot( g++, times, 1.0, 1,    16,   INSERT_BACK,  &amp;quot;misc.cols[2]&amp;quot;, 21 );&lt;br /&gt;
   Rplot( g++, times, 2.0, 0,    1024, INSERT_BACK,  &amp;quot;misc.cols[3]&amp;quot;, 19 );&lt;br /&gt;
   Rplot( g++, times, 1.0, 1000, 16,   INSERT_BACK,  &amp;quot;misc.cols[4]&amp;quot;, 20 );&lt;br /&gt;
 &lt;br /&gt;
   printf( &amp;quot;title(main=\&amp;quot;Insert into an ArrayList\\nfactor+incr[min], position\&amp;quot;)\n&amp;quot; );&lt;br /&gt;
   printf( &amp;quot;legend( \&amp;quot;topleft\&amp;quot;, legend=leg.txt, pch=leg.pch, col=leg.col )\n&amp;quot; );&lt;br /&gt;
 &lt;br /&gt;
   return 0;&lt;br /&gt;
 }&lt;/div&gt;</summary>
		<author><name>Mark</name></author>
	</entry>
</feed>