<?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; C Programing</title>
	<atom:link href="http://geeksplanet.net/tag/c-programing/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>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>
