<?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%3Aapra102</id>
	<title>SE250:lab-4:apra102 - 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%3Aapra102"/>
	<link rel="alternate" type="text/html" href="https://wiki.kram.nz/index.php?title=SE250:lab-4:apra102&amp;action=history"/>
	<updated>2026-04-28T23:56:32Z</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:apra102&amp;diff=6006&amp;oldid=prev</id>
		<title>Mark: 9 revision(s)</title>
		<link rel="alternate" type="text/html" href="https://wiki.kram.nz/index.php?title=SE250:lab-4:apra102&amp;diff=6006&amp;oldid=prev"/>
		<updated>2008-11-03T05:19:33Z</updated>

		<summary type="html">&lt;p&gt;9 revision(s)&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;==Task 1==&lt;br /&gt;
&lt;br /&gt;
Hmmmmm to start with when I looked at the lab tasks sheet I am kind of lost, later I read the whole paper twice that i could do that lab with in time. This is a lengthy. I find this lab really hard to understand. Especially  tasks after 3. Any how i tried to manage up to task 4 but later I am lost. I really had a hard time to understand this linked lists especially that find and copy list.&lt;br /&gt;
To find the length of list I wrote a function as follows:&lt;br /&gt;
&lt;br /&gt;
 int length(Cons* list) {&lt;br /&gt;
 	int len =0;&lt;br /&gt;
 	for( ; list!=nil; list =list-&amp;gt;tail){&lt;br /&gt;
 		len++;&lt;br /&gt;
 	}&lt;br /&gt;
 	return len;&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
==Task 2==&lt;br /&gt;
&lt;br /&gt;
To find the elements in the named functions I tried for a long time. I got the concept theoretically but I was unable to code it. But when I asked the tutor it seemed to be really easy. And I came up with the code as follows: &lt;br /&gt;
&lt;br /&gt;
 element_t first(Cons* list){&lt;br /&gt;
 	return list-&amp;gt;head;&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 element_t second(Cons* list){&lt;br /&gt;
 	return list-&amp;gt;tail-&amp;gt;head;&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 element_t third(Cons* list){&lt;br /&gt;
 	return list-&amp;gt;tail-&amp;gt;tail-&amp;gt;head;&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 element_t fourth(Cons* list){&lt;br /&gt;
 	return list-&amp;gt;tail-&amp;gt;tail-&amp;gt;tail-&amp;gt;head;&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Task 3==&lt;br /&gt;
&lt;br /&gt;
I even really had a hard time understanding this nth element. Which I really couldn&amp;#039;t do for a long time, finally I came up with the following code:&lt;br /&gt;
&lt;br /&gt;
 element_t nth(int i, Cons* list){&lt;br /&gt;
 	while(i !=0){&lt;br /&gt;
 		list = list-&amp;gt;tail;&lt;br /&gt;
 		i--;&lt;br /&gt;
 	}&lt;br /&gt;
  	return list-&amp;gt;head;&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
==Task 4==&lt;br /&gt;
&lt;br /&gt;
Equal function, by the time i came up to this task I am short of time to complete the rest of tasks, but still i tried to do that for a while, I got up to certain point. Should make a function that returns true or false. So, I should use a ‘for’ or a &amp;#039;While&amp;#039;  loop thats what I got in my mind. I got an  idea but hard to put in to a code. I got the following as code for this: &lt;br /&gt;
&lt;br /&gt;
 int equal(Cons* list1, Cons* list2){&lt;br /&gt;
 	while((list1 !=nil) &amp;amp;&amp;amp; (list2 !=nil)){&lt;br /&gt;
 &lt;br /&gt;
 		if(list1-&amp;gt;head ==list2-&amp;gt;head){&lt;br /&gt;
 			list1 = list1-&amp;gt;tail;&lt;br /&gt;
 			list2 = list2-&amp;gt;tail;&lt;br /&gt;
 			return 1;&lt;br /&gt;
 		}&lt;br /&gt;
  		else{&lt;br /&gt;
 			return 0;&lt;br /&gt;
 		}&lt;br /&gt;
 	}&lt;br /&gt;
 	&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
Up to here I did quite ok. But later i couldn&amp;#039;t do any thing.&lt;br /&gt;
&lt;br /&gt;
==Main Function==&lt;br /&gt;
&lt;br /&gt;
 int main( ) {&lt;br /&gt;
     Cons* list  =  cons(1,cons(2,cons(3,nil)));&lt;br /&gt;
     Cons* list2  =  cons(4,cons(5,cons(7,nil)));&lt;br /&gt;
     Cons* list3  =  cons(1, cons(2,cons(3,cons(4,nil))));&lt;br /&gt;
     Cons* search;&lt;br /&gt;
 &lt;br /&gt;
     print_list(list ); /* expect: List[1,2,3] */&lt;br /&gt;
     printf(&amp;quot;Length = %d\n&amp;quot;, length( list )); /* should return 3 */&lt;br /&gt;
     printf(&amp;quot;%d\n&amp;quot;,first(list));&lt;br /&gt;
     printf(&amp;quot;%d\n&amp;quot;,second(list));&lt;br /&gt;
     printf(&amp;quot;%d\n&amp;quot;, third(list));&lt;br /&gt;
     printf(&amp;quot;%d\n&amp;quot;, fourth(list));&lt;br /&gt;
     printf(&amp;quot;%d\n&amp;quot;, nth(1, list));&lt;br /&gt;
     printf(&amp;quot;%d\n&amp;quot;, nth(2, list));&lt;br /&gt;
     printf(&amp;quot;%d\n&amp;quot;, nth(0, list));&lt;br /&gt;
 &lt;br /&gt;
     printf(&amp;quot;\nEqual test:\n&amp;quot;);&lt;br /&gt;
     printf(&amp;quot;%d\n&amp;quot;, equal(list, list2));&lt;br /&gt;
     printf(&amp;quot;%d\n&amp;quot;, equal(list, list3));&lt;br /&gt;
     printf(&amp;quot;%d\n&amp;quot;, equal(list, list));&lt;br /&gt;
     printf(&amp;quot;%d\n&amp;quot;, equal(list2, list3));&lt;br /&gt;
     return 0;&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
I used these &amp;#039;&amp;#039;&amp;#039;printf&amp;#039;&amp;#039;&amp;#039;  functions to test my functionswhich I did up to now.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Conclusion==&lt;br /&gt;
&lt;br /&gt;
Over all I found this lab lengthy. But a good exercise on linked lists. It was a good lab to understand how these Linked Lists works but, up to now I don&amp;#039;t have a clear idea how to do these stuff work. But in the next lecture when the lecture taught about the whole copy, find and lookup functions i got an idea, but still I need some practice on this topic and a clear idea of what I am suppose to do.&lt;/div&gt;</summary>
		<author><name>Mark</name></author>
	</entry>
</feed>