<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>GeeksPlanet.net &#187; Data Structures</title>
	<atom:link href="http://geeksplanet.net/category/data-structures/feed/" rel="self" type="application/rss+xml" />
	<link>http://geeksplanet.net</link>
	<description>C, C++, JAVA, PERL programming for Dummies</description>
	<lastBuildDate>Wed, 24 Feb 2010 11:38:59 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>simple Implementation of stack using a linked list</title>
		<link>http://geeksplanet.net/2008/12/data-structures/simple-implementation-of-stack-using-a-linked-list/</link>
		<comments>http://geeksplanet.net/2008/12/data-structures/simple-implementation-of-stack-using-a-linked-list/#comments</comments>
		<pubDate>Thu, 04 Dec 2008 09:13:37 +0000</pubDate>
		<dc:creator>Satish Gandham</dc:creator>
				<category><![CDATA[C++]]></category>
		<category><![CDATA[Data Structures]]></category>
		<category><![CDATA[Single linked list]]></category>
		<category><![CDATA[Stack]]></category>

		<guid isPermaLink="false">http://geeksplanet.net/?p=63</guid>
		<description><![CDATA[Stacks are linear data structures. This means that their contexts are stored in what looks like a line (although vertically). This linear property, however, is not sufficient to discriminate a stack from other linear data structures. For example, an array is a sort of linear data structure in which you can access any element directly. [...]]]></description>
			<content:encoded><![CDATA[<p><strong>Stacks</strong> are linear data structures. This means that their contexts are stored in what looks like a line (although vertically). This linear property, however, is not sufficient to discriminate a stack from other linear data structures. For example, an array is a sort of linear data structure in which you can access any element directly. In contrast, in a stack, you can only access the element at its top. In a stack <em>Last</em> thing <em>In</em> is the <em>First</em> thing <em>Out</em>.  Thus, we say that a stack enforces <strong>LIFO</strong> order.</p>
<p style="text-align: center;"><a href="http://geeksplanet.net/wp-content/uploads/2008/12/stack.gif"><img class="size-full wp-image-72 aligncenter" title="Stacks | Data Structures" src="http://geeksplanet.net/wp-content/uploads/2008/12/stack.gif" alt="" width="500" height="250" /></a></p>
<p>One disadvantage of <a href="http://geeksplanet.net/2008/09/c-programming/implementaion-of-stack-as-an-array-in-c-language/">implementing stack using an array</a> is wastage of space. Most of the times most of the array is left unused. A better way to implement stack is by using a <a href="http://geeksplanet.net/2008/11/data-structures/implementation-of-singly-linked-list-in-c-plus-plus/">linked list</a>. By using a single linked list to implement a stack there is no wastage of space.</p>
<div id="attachment_62" class="wp-caption aligncenter" style="width: 510px"><a href="http://geeksplanet.net/wp-content/uploads/2008/12/linked-list.gif"><img class="size-full wp-image-62" title="linked-list" src="http://geeksplanet.net/wp-content/uploads/2008/12/linked-list.gif" alt="Implementation of stack using a linked list" width="500" height="150" /></a><p class="wp-caption-text">Implementation of stack using a linked list</p></div>
<pre>
<pre class="brush: cpp;">
/*
A simple implementation of linked list in C plus plus (CPP/C++)
*/
/*
Compiler used: g++
*/
#include&lt;iostream&gt;
using namespace std;
struct node{
	int data;
	node *next;
	};
//This function pushes data(node) to the stack
node * push(node*,node*);
//This function pops data (node) and returns pointer to the poped node
node * pop(node*);
//This function shows the stack
void show_stack(node*);
///These two global variables will help us track the start and end of the list
node *f,*l;
main()
{
	int i,ch;
	f=l=NULL;
	cout&lt;&lt;&quot;\t 1 to push&quot;&lt;&lt;endl;
	cout&lt;&lt;&quot;\t 2 to pop&quot;&lt;&lt;endl;
	cout&lt;&lt;&quot;\t 3 to show stack&quot;&lt;&lt;endl;
	cout&lt;&lt;&quot;\t 0 to exit&quot;&lt;&lt;endl;
	while(1)
	{
		cout&lt;&lt;&quot;Enter your choice:&quot;;
		cin&gt;&gt;ch;
		switch(ch)
		{
		case 1:
			{
			if(f==NULL)
			l=f=push(f,l);
			else
			l=push(f,l);
			break;
			}
		case 2:
			{
			cout&lt;&lt;&quot;popped:&quot;&lt;&lt;pop(f)-&gt;data&lt;&lt;endl;
			break;
			}

		case 3:
			{
			show_stack(f);
			break;
			}
		case 0:
			break;
		default:
			cout&lt;&lt;&quot;Please enter a proper choice&quot;&lt;&lt;endl;break;
		}
		if(ch==0)
		break;
	}
}
node * push(node *f,node *l)
{
	node *n;
	n=new node;
	cout&lt;&lt;&quot;Enter data:&quot;;
	cin&gt;&gt;n-&gt;data;
	n-&gt;next=NULL;
	if(f==NULL)
	{f=l=n;return f;}
	else
	{
		l-&gt;next=n;
		l=n;return l;
	}

}
void show_stack(node *f)
{
	cout&lt;&lt;&quot;showing data&quot;&lt;&lt;endl;
	node *guest=f;
	while(guest!=NULL)
	{
		cout&lt;&lt;&quot;\t&quot;&lt;&lt;guest-&gt;data&lt;&lt;endl;
		guest=guest-&gt;next;
	}
}
node * pop(node *f)
{
	node *guest,*lb;
	guest=lb=f;
	while(guest-&gt;next!=NULL)
	{
		lb=guest;
		guest=guest-&gt;next;
	}
	lb-&gt;next=NULL;
	l=lb;
	return guest;
}
		</pre>
</pre>
<blockquote><p><strong>Download the program:</strong> <a href="http://geeksplanet.net/wp-content/uploads/2008/12/linked-list-as-a-stack.cpp">Implementation of stack using a single linked list</a></p></blockquote>
]]></content:encoded>
			<wfw:commentRss>http://geeksplanet.net/2008/12/data-structures/simple-implementation-of-stack-using-a-linked-list/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>Implementation of Singly linked list in C plus plus</title>
		<link>http://geeksplanet.net/2008/11/data-structures/implementation-of-singly-linked-list-in-c-plus-plus/</link>
		<comments>http://geeksplanet.net/2008/11/data-structures/implementation-of-singly-linked-list-in-c-plus-plus/#comments</comments>
		<pubDate>Fri, 07 Nov 2008 21:20:48 +0000</pubDate>
		<dc:creator>Satish Gandham</dc:creator>
				<category><![CDATA[C++]]></category>
		<category><![CDATA[Data Structures]]></category>
		<category><![CDATA[Linked List]]></category>

		<guid isPermaLink="false">http://geeksplanet.net/?p=37</guid>
		<description><![CDATA[The simplest kind of linked list is a singly-linked list , which has one link per node. This link points to the next node in the list, or to a null value or empty list if it is the final node.A singly linked list&#8217;s node is divided into two parts. The first part holds or [...]]]></description>
			<content:encoded><![CDATA[<p>The simplest kind of <strong>linked list</strong> is a <strong>singly-linked list </strong>, which has one link per node. This link points to the next node in the list, or to a null value or empty list if it is the final node.A singly linked list&#8217;s node is divided into two parts. The first part holds or points to information about the node, and second part holds the address of next node. A singly linked list travels one way.</p>
<blockquote>
<div id="attachment_38" class="wp-caption aligncenter" style="width: 418px"><a href="http://geeksplanet.net/wp-content/uploads/2008/11/singly-linked-list.png"><img class="size-full wp-image-38" title="singly linked list" src="http://geeksplanet.net/wp-content/uploads/2008/11/singly-linked-list.png" alt="A singly-linked list containing two values: the value of the current node and a link to the next node" width="408" height="41" /></a><p class="wp-caption-text">A singly-linked list containing two values: the value of the current node and a link to the next node</p></div></blockquote>
<pre>
<pre class="brush: cpp;">
/*

A simple implementation of linked list in C plus plus (CPP/C++)

*/
/*
Program downloaded from www.GeeksPlanet.net
For any help, post comment here

http://geeksplanet.net/2008/11/data-structures/implementation-of-singly-linked-list-using-c-plus-plus/

Compiler used: g++
*/
#include&lt;iostream&gt;
using namespace std;
struct node{
	int data;
	node *next;
	};
/*
This function adds a node at the end of the
list and returns pointer to the added node,
This takes pointer to the first node and
pointer to the last node as argument. By
giving the last node as argument we are saving
some computer labour as it need not travel
from the start to the end to find the last node
*/
node * addnode(node*,node*);
/*
This function just takes the first node as
the argument and traverses the entire list
displaying the data in each node.
*/
void shownodes(node*);
/*
This function takes the first node as argument
and traverses the list until it finds the last
node and deletes it and returns pointer to the
new last node.
*/
node * delete_node(node*);
/*
*f and *l are the global variables keeping track
of first and last nodes.
*/
node *f,*l;

main()
{
	int i,ch;
	f=l=NULL;
	cout&lt;&lt;&quot;\t 1 to add a node&quot;&lt;&lt;endl;
	cout&lt;&lt;&quot;\t 2 to see the nodes&quot;&lt;&lt;endl;
	cout&lt;&lt;&quot;\t 3 to delete a node&quot;&lt;&lt;endl;
	cout&lt;&lt;&quot;\t 0 to exit&quot;&lt;&lt;endl;
	while(1)
	{
		cout&lt;&lt;&quot;Enter your choice:&quot;;
		cin&gt;&gt;ch;
		switch(ch)
		{
		case 1:
		{
			if(f==NULL)
			l=f=addnode(f,l); //Since first node is the last node
			else
			l=addnode(f,l);	  //Last node is the new node added
			break;
		}
		case 2:
			shownodes(f);break;
		case 3:
			l=delete_node(f);break; // Last node has been changed to the last but one.
		case 0:
			break;
		default:
			cout&lt;&lt;&quot;Please enter a proper choice&quot;&lt;&lt;endl;break;
		}
		if(ch==0)
		break;
	}
}
node * addnode(node *f,node *l)
{
	node *n;
	n=new node;
	//Allocating memory for the new node
	cout&lt;&lt;&quot;Enter data:&quot;;
	cin&gt;&gt;n-&gt;data;
        //This is going to be the last node, so its next point to NULL
	n-&gt;next=NULL;
	//If there is no first node, then the new node is the first and last node.
	if(f==NULL)
	{f=l=n;return f;}
	else
	{
		// Pointing the last node to the new node
		l-&gt;next=n;
		//Setting the new node as the last node
		l=n;return l;
	}

}
void shownodes(node *f)
{
	cout&lt;&lt;&quot;showing data&quot;&lt;&lt;endl;
	node *guest=f;
	while(guest!=NULL)
	{
		cout&lt;&lt;&quot;\t&quot;&lt;&lt;guest-&gt;data&lt;&lt;endl;
		guest=guest-&gt;next;
	}
}
node * delete_node(node *f)
{
	node *guest,*lb;
	guest=lb=f;
	while(guest-&gt;next!=NULL)
	{
		lb=guest;
		guest=guest-&gt;next;
	}
	lb-&gt;next=NULL;
	cout&lt;&lt;&quot;node deleted&quot;&lt;&lt;endl;
	return lb;
}
</pre>
</pre>
<blockquote>
<p style="text-align: center;"><strong>Download the prgoram <a href="http://geeksplanet.net/wp-content/uploads/2008/11/linked-list.cpp">linked-list.cpp</a></strong></p>
</blockquote>
]]></content:encoded>
			<wfw:commentRss>http://geeksplanet.net/2008/11/data-structures/implementation-of-singly-linked-list-in-c-plus-plus/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Program to convert infix expression to postfix in C &#124; Shunting yard algorithm</title>
		<link>http://geeksplanet.net/2008/10/c-programming/program-to-convert-infix-expression-to-postfix-in-c-shunting-yard-algorithm/</link>
		<comments>http://geeksplanet.net/2008/10/c-programming/program-to-convert-infix-expression-to-postfix-in-c-shunting-yard-algorithm/#comments</comments>
		<pubDate>Sun, 19 Oct 2008 04:46:37 +0000</pubDate>
		<dc:creator>Satish Gandham</dc:creator>
				<category><![CDATA[C-Programming]]></category>
		<category><![CDATA[Data Structures]]></category>
		<category><![CDATA[C Programing]]></category>
		<category><![CDATA[Infix to postfix]]></category>
		<category><![CDATA[Stacks]]></category>

		<guid isPermaLink="false">http://geeksplanet.net/?p=9</guid>
		<description><![CDATA[This program is a implementation of shunting yard algorithm to convert an infix expression to post fix expression, This is a extension of the stack program published earlier
Algorithm:(Taken from wikipedia)


While there are tokens to be read:




Read a  token .
If the token is a number, then add it to the output queue.
If the token is [...]]]></description>
			<content:encoded><![CDATA[<p>This program is a implementation of <strong>shunting yard algorithm</strong> to convert an <strong>infix expression to post fix expression</strong>, This is a extension of the <a href="http://geeksplanet.net/2008/09/c-programming/implementaion-of-stack-as-an-array-in-c-language/">stack program</a> published earlier</p>
<p><strong>Algorithm:(Taken from<a href="http://en.wikipedia.org/wiki/Shunting_yard_algorithm"> wikipedia</a>)<br />
</strong></p>
<ul>
<li>While there are tokens to be read:</li>
</ul>
<dl>
<dd>
<ul>
<li>Read a  token .</li>
<li>If the token is a number, then add it to the output queue.</li>
<li>If the token is a function  token, then push it onto the stack.</li>
<li>If the token is a function argument separator (e.g., a comma):</li>
</ul>
<dl>
<dd>
<ul>
<li>Until the topmost element of the stack is a left parenthesis, pop the element from the stack and push it onto the output queue. If no left parentheses are encountered, either the separator was misplaced or parentheses were mismatched.</li>
</ul>
</dd>
</dl>
<ul>
<li>If the token is an operator, o<sub>1</sub>, then:</li>
</ul>
<dl>
<dd>
<ul>
<li>while there is an operator, o<sub>2</sub>, at the top of the stack, and either</li>
</ul>
<dl>
<dd>
<dl>
<dd>
<dl>
<dd>o<sub>1</sub> is associative or left-associative and its precedence is less than (lower precedence) or equal to that of o<sub>2</sub>, or</dd>
<dd>o<sub>1</sub> is right-associative and its precedence is less than (lower precedence) that of o<sub>2</sub>, </dd>
</dl>
</dd>
<dd>pop o<sub>2</sub> off the stack, onto the output queue;</dd>
</dl>
</dd>
</dl>
<ul>
<li>push o<sub>1</sub> onto the stack.</li>
</ul>
</dd>
</dl>
<ul>
<li>If the token is a left parenthesis, then push it onto the stack.</li>
<li>If the token is a right parenthesis:</li>
</ul>
<dl>
<dd>
<ul>
<li>Until the token at the top of the stack is a left parenthesis, pop operators off the stack onto the output queue.</li>
<li>Pop the left parenthesis from the stack, but not onto the output queue.</li>
<li>If the token at the top of the stack is a function token, pop it and onto the output queue.</li>
<li>If the stack runs out without finding a left parenthesis, then there are mismatched parentheses.</li>
</ul>
</dd>
</dl>
</dd>
</dl>
<ul>
<li>When there are no more tokens to read:</li>
</ul>
<dl>
<dd>
<ul>
<li>While there are still operator tokens in the stack:</li>
</ul>
<dl>
<dd>
<ul>
<li>If the operator token on the top of the stack is a parenthesis, then there are mismatched parenthesis.</li>
<li>Pop the operator onto the output queue.</li>
</ul>
</dd>
</dl>
</dd>
</dl>
<ul>
<li>Exit.</li>
</ul>
<pre>
<pre class="brush: cpp;">#include &lt;stdio.h&gt;
#define size 10
char stack[size];
int tos=0,ele;
void push();
char pop();
void show();
int isempty();
int isfull();
char infix[30],output[30];
int prec(char);
int main()
{
                int i=0,j=0,k=0,length;
                char temp;
                printf(&quot;\nEnter an infix expression:&quot;);
                scanf(&quot;%s&quot;,infix);
                printf(&quot;\nThe infix expresson is %s&quot;,infix);
                length=strlen(infix);
                for(i=0;i&lt;= prec(stack[tos-1])  )
						{
						temp=pop();
                                                printf(&quot;\n the poped element is :%c&quot;,temp);
                                                output[j++]=temp;
						push(infix[i]);
						printf(&quot;\n The pushed element is :%c&quot;,infix[i]);
                                                show();
						}
						else
						{
						push(infix[i]);
						printf(&quot;\nThe pushed element is:%c&quot;,infix[i]);
                                                show();
						}
					}
					else
					{
						if(infix[i]=='(')
						{
                                                push(infix[i]);
                                                printf(&quot;\nThe pushed-- element is:%c&quot;,infix[i]);
                                                }
						if(infix[i]==')')
						{
						temp=pop();
                                                while(temp!='(')
                                               {output[j++]=temp;
                                                printf(&quot;\nThe element added to Q is:%c&quot;,temp);
                                                //temp=pop();
						printf(&quot;\n the poped element is :%c&quot;,temp);
						temp=pop();}
						}
					}
				}
			}
 printf(&quot;\nthe infix expression is: %s&quot;,output);
		}
		while(tos!=0)
		{
			output[j++]=pop();
		}
printf(&quot;the infix expression is: %s\n&quot;,output);
}
//Functions for operations on stack
void push(int ele)
{
	stack[tos]=ele;
	tos++;
}
char pop()
{
	tos--;
	return(stack[tos]);
}
void show()
{
	int x=tos;
	printf(&quot;--The Stack elements are.....&quot;);
	while(x!=0)
	printf(&quot;%c, &quot;,stack[--x]);
}

//Function to get the precedence of an operator
int prec(char symbol)
{
if(symbol== '(')
return 0;
if(symbol== ')')
return 0;
if(symbol=='+' || symbol=='-')
return 1;
if(symbol=='*' || symbol=='/')
return 2;
if(symbol=='^')
return 3;
return 0;
}</pre>
</pre>
<p><a href="http://geeksplanet.net/wp-content/uploads/2008/10/infix-to-postfix.c"></a></p>
<blockquote><p><a href="http://geeksplanet.net/wp-content/uploads/2008/10/infix-to-postfix.c">Download the Program <strong>Infix-to-postfix.c</strong></a></p></blockquote>
]]></content:encoded>
			<wfw:commentRss>http://geeksplanet.net/2008/10/c-programming/program-to-convert-infix-expression-to-postfix-in-c-shunting-yard-algorithm/feed/</wfw:commentRss>
		<slash:comments>16</slash:comments>
		</item>
		<item>
		<title>Implementaion of Stack as an Array in C language</title>
		<link>http://geeksplanet.net/2008/09/c-programming/implementaion-of-stack-as-an-array-in-c-language/</link>
		<comments>http://geeksplanet.net/2008/09/c-programming/implementaion-of-stack-as-an-array-in-c-language/#comments</comments>
		<pubDate>Mon, 01 Sep 2008 18:11:17 +0000</pubDate>
		<dc:creator>Satish Gandham</dc:creator>
				<category><![CDATA[C-Programming]]></category>
		<category><![CDATA[Data Structures]]></category>
		<category><![CDATA[C Programing]]></category>
		<category><![CDATA[Stacks]]></category>

		<guid isPermaLink="false">http://geeksplanet.net/?p=7</guid>
		<description><![CDATA[

/////////////////////////////////////////////////////

// Implementation of stack(containing names) as an //

// array, with its basic operations PUSH,POP and   //

// also the IS_EMPTY and IS_FULL operations.       //

// Program written by Satish Gandham on 01-09-08   //

// Feel free to modify or use it directly       [...]]]></description>
			<content:encoded><![CDATA[<pre>
<pre class="brush: cpp;">
/////////////////////////////////////////////////////

// Implementation of stack(containing names) as an //

// array, with its basic operations PUSH,POP and   //

// also the IS_EMPTY and IS_FULL operations.       //

// Program written by Satish Gandham on 01-09-08   //

// Feel free to modify or use it directly          //

// Program compiled with GCC Compiler              //

/////////////////////////////////////////////////////

#include&lt;stdio.h&gt;
#define size 5
char stack[size][15],ele[20];
int tos;
void push();
char* pop();
void show();
int isempty();
int isfull();

int main()
{
	int choice;
	tos=0;
	do
	{
		printf(&quot;\tEnter 1 for push,2 for pop,3 to show,and 4 to exit\n&quot;);
		scanf(&quot;%d&quot;,&amp;choice);
		switch(choice)
		{
		case 1:
		if (isfull())
		printf(&quot;\nThe stack is full&quot;);
		else
			{
		printf(&quot;\n Enter element to insert&quot;);
		scanf(&quot;%s&quot;,ele);
		push(ele);
			}
		break;
		case 2:
		if(isempty())
		printf(&quot;\n The stack is empty&quot;);
		else
		printf(&quot;\nThe removed element is:%s&quot;,pop());
		break;
		case 3:
		if(isempty())
		printf(&quot;\nThe stack is empty, I cant show you any elements&quot;);
		else
		show();
		break;
		case 4:
		exit(1);
		default:
		printf(&quot;\nDo you understand english and numbers??&quot;);
		}
	}while(1);
}
int isempty()
{
	return(tos==0);
}
int isfull()
{
	return(tos==size);
}
void push(ele)
{
	//stack[tos]=ele;
	strcpy(stack[tos],ele);
	tos++;
}
char* pop()
{
	tos--;
	return(stack[tos]);
}
void show()
{
	int x=tos;
	printf(&quot;\nThe Stack elements are.....\n&quot;);
	while(x!=0)
	printf(&quot;\t%s\n&quot;,stack[--x]);
}
</pre>
</pre>
<blockquote style="text-align: center;"><p><strong><a href="http://geeksplanet.net/wp-content/uploads/2008/09/stack-array.c">Download the Program</a></strong></p></blockquote>
]]></content:encoded>
			<wfw:commentRss>http://geeksplanet.net/2008/09/c-programming/implementaion-of-stack-as-an-array-in-c-language/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
	</channel>
</rss>
