<?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-4%3Amspe044</id>
	<title>SE250:lab-4:mspe044 - 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-4%3Amspe044"/>
	<link rel="alternate" type="text/html" href="https://wiki.kram.nz/index.php?title=SE250:lab-4:mspe044&amp;action=history"/>
	<updated>2026-04-28T17:13:27Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.45.3</generator>
	<entry>
		<id>https://wiki.kram.nz/index.php?title=SE250:lab-4:mspe044&amp;diff=6132&amp;oldid=prev</id>
		<title>Mark: 2 revision(s)</title>
		<link rel="alternate" type="text/html" href="https://wiki.kram.nz/index.php?title=SE250:lab-4:mspe044&amp;diff=6132&amp;oldid=prev"/>
		<updated>2008-11-03T05:19:36Z</updated>

		<summary type="html">&lt;p&gt;2 revision(s)&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;Lab 4 (Linked List (single))&lt;br /&gt;
&lt;br /&gt;
--------------------------------------------------------------------------------------------------------------------&lt;br /&gt;
&lt;br /&gt;
Task One: function int Length(cons*)&lt;br /&gt;
&lt;br /&gt;
This function was verry hard for me (as I have missed the last four lectures : /, but after a nice spell on&lt;br /&gt;
wikipedia and a minute of tutorial help I was on my way (and 20 minutes trying to understand what a linked list was&lt;br /&gt;
:P) The linked lists once I understood them fell into place, and I stole large sections of the code from the already&lt;br /&gt;
existing print_list function in the file. My final code was this&lt;br /&gt;
&lt;br /&gt;
 int length(Cons* list ) { /* Hopefully works (Returns list length) */&lt;br /&gt;
  int counter = 0;&lt;br /&gt;
 &lt;br /&gt;
  for( ; list != nil; list = list-&amp;gt;tail ) {&lt;br /&gt;
    counter++;&lt;br /&gt;
  }&lt;br /&gt;
  return counter;&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
It worked well, pleased with it and now I understand what a linked list is, I can move onto the rest of the tasks...&lt;br /&gt;
&lt;br /&gt;
--------------------------------------------------------------------------------------------------------------------&lt;br /&gt;
&lt;br /&gt;
Task Two: element_t first(Cons*) &amp;amp; 2nd &amp;amp; 3rd &amp;amp; 4th...&lt;br /&gt;
&lt;br /&gt;
At first view it looked alot more logical to do a element nth than 4 functions to me but hay, thats the task, ironic&lt;br /&gt;
that the verry next task was a element nth but hay, such is life...&lt;br /&gt;
&lt;br /&gt;
Anyhow I did my code (it was beutiful cleanly using 1/2 a screen of if statements to check for nil in a loop and if&lt;br /&gt;
a nil was found putting 0 in the return veriable...) then I was told that the code already converted nil to 0 and I&lt;br /&gt;
should delete most of the code, my if statements, my veriables... it was a sad moment :p but still worked like a&lt;br /&gt;
charm with the fat cut out... guess I should read the code more before I start next time huh&lt;br /&gt;
&lt;br /&gt;
 element_t first(Cons* list) { /* Hopefully gives the first element */&lt;br /&gt;
 &lt;br /&gt;
   return list-&amp;gt;head;&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 element_t second(Cons* list) { /* Hopefully gives the first element */&lt;br /&gt;
   int counter;&lt;br /&gt;
 &lt;br /&gt;
   for( counter = 1; counter != 2; counter++ ) {&lt;br /&gt;
     list = list-&amp;gt;tail;&lt;br /&gt;
   }&lt;br /&gt;
&lt;br /&gt;
   return list-&amp;gt;head;&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
This is my optomised code.&lt;br /&gt;
&lt;br /&gt;
--------------------------------------------------------------------------------------------------------------------&lt;br /&gt;
&lt;br /&gt;
Task Three: element_t nth(Cons*)&lt;br /&gt;
&lt;br /&gt;
Well this was ALWAYS gona follow on behind the 4 function mamoth that was task two, but required one or two tweeks&lt;br /&gt;
and a additional imput veriable and presto, finshed... no big deal here.&lt;br /&gt;
&lt;br /&gt;
 element_t nth(int i, Cons* list) { /* Hopefully gives the first element */&lt;br /&gt;
   int counter;&lt;br /&gt;
 &lt;br /&gt;
   for( counter = 1; counter != i; counter++ ) {&lt;br /&gt;
     list = list-&amp;gt;tail;&lt;br /&gt;
   }&lt;br /&gt;
 &lt;br /&gt;
   return list-&amp;gt;head;&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
There is nothing buch to say about this one, its task two with a different flavor...&lt;br /&gt;
&lt;br /&gt;
--------------------------------------------------------------------------------------------------------------------&lt;br /&gt;
&lt;br /&gt;
Task Four: Check Lists are Equal&lt;br /&gt;
&lt;br /&gt;
This task just involved steeling my code from task one, with one minor complication... WTF do you do to optomise the&lt;br /&gt;
nil check...&lt;br /&gt;
&lt;br /&gt;
 int equal(Cons* list1, Cons* list2) { /* Hopefully works (Returns list length) */&lt;br /&gt;
 &lt;br /&gt;
   for( ; (list1 != nil); list1 = list1-&amp;gt;tail ) {&lt;br /&gt;
     if (( list1-&amp;gt;head != list2-&amp;gt;head )) {&lt;br /&gt;
       return 0;&lt;br /&gt;
     }&lt;br /&gt;
     list2 = list2-&amp;gt;tail;&lt;br /&gt;
   }&lt;br /&gt;
   return 1;&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
This code is wrong, I knew it was wrong and I knew 100 ways to fix it... but none of them would fix it nicely...&lt;br /&gt;
You see it all works well if list1 and list2 are the same length... but what if list1 is longer or shorter than&lt;br /&gt;
list2?!?!? I can put in long winded if statements etc to check both are not at a nul value... but that would take&lt;br /&gt;
forever to wright (at least a minute!!!) and would slow the program... and that will NOT do!&lt;br /&gt;
&lt;br /&gt;
So I just went...&lt;br /&gt;
&lt;br /&gt;
 int equal(Cons* list1, Cons* list2) { /* Hopefully works (Returns list length) */&lt;br /&gt;
 &lt;br /&gt;
   for( ; (list1 != nil) | (list2 != nil); list1 = list1-&amp;gt;tail ) {&lt;br /&gt;
     if (( list1-&amp;gt;head != list2-&amp;gt;head )) {&lt;br /&gt;
       return 0;&lt;br /&gt;
     }&lt;br /&gt;
     list2 = list2-&amp;gt;tail;&lt;br /&gt;
   }&lt;br /&gt;
   return 1;&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
The key difference is in the for statement end check, (list1 != nil) | (list2 != nil) as apposed to (list1 != nil)&lt;br /&gt;
thus moving on if BOTH are not at an end, therefore hitting an inevitable difference in the element values (assuming&lt;br /&gt;
the list with extra elements has values put into the head element) not a verry big assumption in my opinion...&lt;br /&gt;
&lt;br /&gt;
If the assumption proves false then it will either pleasntly reach the end with both the head value and the (my list&lt;br /&gt;
is already finshed I DONT HAVE A HEAD) value being equal and finsh or brake, im not sure which...&lt;br /&gt;
As it depends on what happens if you try to run on past the last value of a list-&amp;gt;foot, what happens when you run&lt;br /&gt;
past that all important nil value? does it sit on nil or brake..? havent given it much thought though I think ill&lt;br /&gt;
ask.&lt;br /&gt;
&lt;br /&gt;
--------------------------------------------------------------------------------------------------------------------&lt;br /&gt;
&lt;br /&gt;
Task Five: Not completed, Been here for 3 hours so far and calling it quits (moral of the story dont miss a weaks&lt;br /&gt;
lectures and expect not to fall behind : /&lt;br /&gt;
&lt;br /&gt;
Edit, space every CODE line not evey non code line... that wasted a good 10 minutes o_0&lt;/div&gt;</summary>
		<author><name>Mark</name></author>
	</entry>
</feed>