<?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%3Asrag014</id>
	<title>SE250:lab-4:srag014 - 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%3Asrag014"/>
	<link rel="alternate" type="text/html" href="https://wiki.kram.nz/index.php?title=SE250:lab-4:srag014&amp;action=history"/>
	<updated>2026-06-08T20:34:28Z</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:srag014&amp;diff=6231&amp;oldid=prev</id>
		<title>Mark: 7 revision(s)</title>
		<link rel="alternate" type="text/html" href="https://wiki.kram.nz/index.php?title=SE250:lab-4:srag014&amp;diff=6231&amp;oldid=prev"/>
		<updated>2008-11-03T05:19:38Z</updated>

		<summary type="html">&lt;p&gt;7 revision(s)&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;This Lab is all to do with linked lists, were provided with starter code and then told to implent different functions.&lt;br /&gt;
&lt;br /&gt;
===Task1===&lt;br /&gt;
&lt;br /&gt;
 int length(Cons* list){&lt;br /&gt;
 int x=0;&lt;br /&gt;
 if(list-&amp;gt;tail == nil){&lt;br /&gt;
 return 0;&lt;br /&gt;
 }&lt;br /&gt;
 else for(; list != nil; list = list-&amp;gt;tail){&lt;br /&gt;
 x=x+1;&lt;br /&gt;
 }&lt;br /&gt;
 return x;&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
I tested the function the function by inserting 4 linked lists and it returned with a value of 4 which in this case is the desired output.&lt;br /&gt;
&lt;br /&gt;
===Task 2===&lt;br /&gt;
&lt;br /&gt;
Second task pretty much involved writing three functions namely element t first(Cons*), element t second(Cons*),element t third(Cons*), and element t fourth(Cons*) returning the element.&lt;br /&gt;
&lt;br /&gt;
 element_t first(Cons* list) {&lt;br /&gt;
 if(list == nil) {&lt;br /&gt;
 return 0;&lt;br /&gt;
 }&lt;br /&gt;
 return list-&amp;gt;head;&lt;br /&gt;
 }&lt;br /&gt;
 element_t second(Cons* list) {&lt;br /&gt;
 if(list == nil) {&lt;br /&gt;
 return 0;&lt;br /&gt;
 }&lt;br /&gt;
 return list-&amp;gt;tail-&amp;gt;head;&lt;br /&gt;
 }&lt;br /&gt;
 element_t third(Cons* list) {&lt;br /&gt;
 if(list == nil) {&lt;br /&gt;
 return 0;&lt;br /&gt;
 }&lt;br /&gt;
 return list-&amp;gt;tail-&amp;gt;tail-&amp;gt;head;&lt;br /&gt;
 } &lt;br /&gt;
 element_t fourth(Cons* list) {&lt;br /&gt;
 if(list == nil) {&lt;br /&gt;
 return 0;&lt;br /&gt;
 }&lt;br /&gt;
 return list-&amp;gt;tail-&amp;gt;tail-&amp;gt;head;&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
===Task 3===&lt;br /&gt;
This task was pretty much similar to the previous one except it is for the nth loop.&lt;br /&gt;
I got really confused with the for loop and how to implent it with the linked list but my neighbour helped me out.&lt;br /&gt;
&lt;br /&gt;
 element_t nth(int i, Cons* list) {&lt;br /&gt;
 int j = 0;&lt;br /&gt;
 Cons *find1 = list;&lt;br /&gt;
 if(list == nil) {&lt;br /&gt;
 return 0;&lt;br /&gt;
 }&lt;br /&gt;
 for(j; j &amp;lt; i; j++) {&lt;br /&gt;
 if(list-&amp;gt;tail == nil) {&lt;br /&gt;
 break;&lt;br /&gt;
 }&lt;br /&gt;
 find1 = find1-&amp;gt;tail;&lt;br /&gt;
 }&lt;br /&gt;
 return find1-&amp;gt;head;&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
===Task 4===&lt;br /&gt;
We had to wirte a function that returns true if both lists have exactly the same elements in the same order, if it not it had to return false.&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;
 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;
 } else {&lt;br /&gt;
 return 0;&lt;br /&gt;
 }&lt;br /&gt;
 } &lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
===Task 5===&lt;br /&gt;
Task 5 involved writing a function to search for an element in the list and return the Cons cell that contains this value, or the empty list if it does not occur in the list.&lt;br /&gt;
This is where i got upto when the time was up. Ill finish this lab later on in the week as theres a bit too many tests/assignments on at the moment&lt;/div&gt;</summary>
		<author><name>Mark</name></author>
	</entry>
</feed>