<?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%3Avpup001</id>
	<title>SE250:lab-4:vpup001 - 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%3Avpup001"/>
	<link rel="alternate" type="text/html" href="https://wiki.kram.nz/index.php?title=SE250:lab-4:vpup001&amp;action=history"/>
	<updated>2026-04-29T02:24:10Z</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:vpup001&amp;diff=6276&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:vpup001&amp;diff=6276&amp;oldid=prev"/>
		<updated>2008-11-03T05:19:39Z</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;== Link lists ==&lt;br /&gt;
&lt;br /&gt;
*The function to return the number of elements in the list.&lt;br /&gt;
 int length(Cons* list) {&lt;br /&gt;
 	 int i = 0;&lt;br /&gt;
 &lt;br /&gt;
         for ( ; list!=nil; list=list-&amp;gt;tail) {&lt;br /&gt;
 		 i++;&lt;br /&gt;
 	 }&lt;br /&gt;
  	 return i;&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
*The functions that returns the elements in the named position (i.e first, second, third, fourth) and returns 0 if no such element exists.&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;
*The function that returns the i&amp;#039;th element in a list or 0 if no such element exists (generalizing the above functions)&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;
The while loop is used to go through every element in the list. If i is not equal to 0 it checks the next element and it does that until i is 0 and returns list-&amp;gt;head.&lt;br /&gt;
&lt;br /&gt;
*The function that returns true if both lists have exactly the same elements in the same order, false otherwise.&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;/div&gt;</summary>
		<author><name>Mark</name></author>
	</entry>
</feed>