<?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%3Atwon069</id>
	<title>SE250:lab-4:twon069 - 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%3Atwon069"/>
	<link rel="alternate" type="text/html" href="https://wiki.kram.nz/index.php?title=SE250:lab-4:twon069&amp;action=history"/>
	<updated>2026-04-28T19:43:15Z</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:twon069&amp;diff=6268&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-4:twon069&amp;diff=6268&amp;oldid=prev"/>
		<updated>2008-11-03T05:19:39Z</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;==length==&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
int length(Cons* list){&lt;br /&gt;
	int length = 0;&lt;br /&gt;
	for( ; list !=nil; list = list-&amp;gt;tail) {&lt;br /&gt;
		length++;&lt;br /&gt;
	}&lt;br /&gt;
	return length;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
*Pretty straight forward, goes through each cells in the list and increase the length by 1 each time.&lt;br /&gt;
&lt;br /&gt;
==element_t first==&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
element_t first(Cons* list){&lt;br /&gt;
	return list-&amp;gt;head;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
*Again, straight forward, just returning the first cell&amp;#039;s head.&lt;br /&gt;
&lt;br /&gt;
==element_t second==&lt;br /&gt;
&amp;lt;pre&amp;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;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
*I wrote an if statement at first returning nil if the list is only 1 cell long.&lt;br /&gt;
*However, realized the following&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
static Cons NIL = { 0, &amp;amp;NIL };&lt;br /&gt;
Cons* nil = &amp;amp;NIL;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
*After realizing a nil cell was already set up, which is always pointing to itself, the code doesn&amp;#039;t need an if statement as the list will continue to go through the NIL cell until the end.&lt;br /&gt;
&lt;br /&gt;
==element_t third and fourth==&lt;br /&gt;
&amp;lt;pre&amp;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;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
*Pretty dull as it just goes through the NIL cell over and over and over again...&lt;br /&gt;
&lt;br /&gt;
==element_t nth==&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
element_t nth(int i, Cons* list){&lt;br /&gt;
	int n;&lt;br /&gt;
	if (i &amp;lt;= 0) {&lt;br /&gt;
		return 0;&lt;br /&gt;
	}&lt;br /&gt;
	for ( n = 0; n &amp;lt; i; n++) {&lt;br /&gt;
		list = list-&amp;gt;tail;&lt;br /&gt;
	}&lt;br /&gt;
	return list-&amp;gt;head;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
*Straight forward, goes through the list until it reaches the cell told and returns the head of it.&lt;br /&gt;
&lt;br /&gt;
==equal==&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
int equal(Cons* listA, Cons* listB){&lt;br /&gt;
	for( ; listA != nil; listA = listA-&amp;gt;tail){&lt;br /&gt;
		if (listA-&amp;gt;head != listB-&amp;gt;head){&lt;br /&gt;
			return 0;&lt;br /&gt;
		}&lt;br /&gt;
		listB = listB-&amp;gt;tail;&lt;br /&gt;
	}&lt;br /&gt;
	if (listA-&amp;gt;tail == listB-&amp;gt;tail) {&lt;br /&gt;
		return 1;&lt;br /&gt;
	}&lt;br /&gt;
	return 0;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
*Had some problem trying to figure out if they both have the same head, however 1 list is longer than the other 1.&lt;br /&gt;
*Problem solved by checking the tail of both list for equality, because if both are the same length and contains the same elements, both should have nil as the tail.&lt;br /&gt;
&lt;br /&gt;
==find==&lt;/div&gt;</summary>
		<author><name>Mark</name></author>
	</entry>
</feed>