<?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>You are not welcome in my world! &#187; Teknik</title>
	<atom:link href="http://blog.ayberkyilmaz.net/category/teknik/feed" rel="self" type="application/rss+xml" />
	<link>http://blog.ayberkyilmaz.net</link>
	<description>things that matter</description>
	<lastBuildDate>Fri, 18 Feb 2011 23:34:42 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3</generator>
		<item>
		<title>Assembly: The very first date!</title>
		<link>http://blog.ayberkyilmaz.net/2011/assembly-the-very-first-date-167</link>
		<comments>http://blog.ayberkyilmaz.net/2011/assembly-the-very-first-date-167#comments</comments>
		<pubDate>Fri, 18 Feb 2011 23:34:02 +0000</pubDate>
		<dc:creator>Ayberk Yılmaz</dc:creator>
				<category><![CDATA[Teknik]]></category>
		<category><![CDATA[assembly]]></category>
		<category><![CDATA[motorola 6800]]></category>

		<guid isPermaLink="false">http://blog.ayberkyilmaz.net/?p=167</guid>
		<description><![CDATA[Today, we wrote and ran our first assembly program. To be honest, since we are used to coding in higher level languages, it seems getting used to assembly will not be easy. However, even though it may get annoying, it is fun! We run our code at Hippy simulator. It simulates a M6800 processor. Despite [...]]]></description>
			<content:encoded><![CDATA[<p>Today, we wrote and ran our first assembly program. To be honest, since we are used to coding in higher level languages, it seems getting used to assembly will not be easy. However, even though it may get annoying, it is fun!</p>
<p>We run our code at Hippy simulator. It simulates a M6800 processor. Despite the fact that we have not learned loops and conditionals yet, I was too curious to wait for the next lectures. Therefore, I tried to write a very simple program that has very basic usage of conditionals and loops. Since I am not familiar with the instructions yet, it took more than necessary time. But it was worth every minute of it and I think I will get along well with assembly.</p>
<p>Now I am representing the source of my program. Thanks to the Hippy, I do not have to load op-codes to memory manually. It compiles the mnemonic codes and loads the op-codes to the memory. I will not explain what code does, actually it may be a good exercise if you try to understand. Well, label names will be very helpful.</p>
<p>P.S: I know this code can be shortened. I was too lazy to improve it and do not forget the fact that this is my first program.</p>
<pre lang = "asm" line="1">
LDAA 100H
LDAB 105H

CBA
BGE AGRE
BRA BGRE

AGRE: SBA
CBA
BGE AGRE
CMPA #0000H
BEQ DIVISIBLE
BRA NONDIVISIBLE

LDAA 105H
LDAB 100H
BGRE: SBA
CBA
BGE BGRE
CMPA #0000H
BEQ DIVISIBLE
BRA NONDIVISIBLE

DIVISIBLE: LDAA #1H
STAA 110H
SWI

NONDIVISIBLE: LDAA #0H
STAA 110H
SWI
</pre>
]]></content:encoded>
			<wfw:commentRss>http://blog.ayberkyilmaz.net/2011/assembly-the-very-first-date-167/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>TopCoder SRM 492 &#8211; TimeTravellingCellar [C++]</title>
		<link>http://blog.ayberkyilmaz.net/2011/topcoder-srm-492-timetravellingcellar-c-163</link>
		<comments>http://blog.ayberkyilmaz.net/2011/topcoder-srm-492-timetravellingcellar-c-163#comments</comments>
		<pubDate>Sun, 30 Jan 2011 00:20:05 +0000</pubDate>
		<dc:creator>Ayberk Yılmaz</dc:creator>
				<category><![CDATA[Teknik]]></category>
		<category><![CDATA[cpp]]></category>
		<category><![CDATA[srm 492]]></category>
		<category><![CDATA[timetravellingcellar]]></category>
		<category><![CDATA[topcoder]]></category>

		<guid isPermaLink="false">http://blog.ayberkyilmaz.net/?p=163</guid>
		<description><![CDATA[Since I am very new to &#8220;algorithm&#8221; world and neither have enough knowledge nor IQ to solve harder questions, I am trying to solve TopCoder DIV II &#8211; Level I questions. They are usually very easy to solve. They do not need any special algorithm knowledge, basic coding approach does work. I will try to [...]]]></description>
			<content:encoded><![CDATA[<p>Since I am very new to &#8220;algorithm&#8221; world and neither have enough knowledge nor IQ to solve harder questions, I am trying to solve TopCoder DIV II &#8211; Level I questions. They are usually very easy to solve. They do not need any special algorithm knowledge, basic coding approach does work.</p>
<p>I will try to explain some of the questions that i solved. I start with the TimeTravellingCellar problem. You can find the problem statement <a href="http://www.topcoder.com/stat?c=problem_statement&amp;pm=11118&amp;rd=14245&amp;rm=306849&amp;cr=22858920" target="_blank">here</a>.</p>
<p>Well if you look at the constraints, you realize that you can solve problem by brute force approah. However i came up with a different and a better solution.</p>
<p>It is clear that in order to find the answer, we need to find to find the max profit and the min decay. By using this simple realization, we can solve the problem in O(N) time. Implementation is even easier than the realization, as it only involves finding maximum and minimum. The only trick is that you cannot time travel in the same cellar, meaning if the cellar with the highest profit contains the lowest decay, you should ignore the cellar with the highest profit while finding the lowest decay profit.</p>
<p>I have implemented my solution in C++.</p>

<div class="wp_syntax"><div class="code"><pre class="cpp" style="font-family:monospace;">	<span style="color: #0000ff;">int</span> max<span style="color: #008000;">&#40;</span>vector<span style="color: #000080;">&lt;</span><span style="color: #0000ff;">int</span><span style="color: #000080;">&gt;</span> profit<span style="color: #008000;">&#41;</span>
	<span style="color: #008000;">&#123;</span>
		<span style="color: #0000ff;">int</span> place<span style="color: #000080;">=</span><span style="color: #0000dd;">0</span><span style="color: #008080;">;</span>
		<span style="color: #0000ff;">int</span> maxi <span style="color: #000080;">=</span> <span style="color: #0000dd;">0</span><span style="color: #008080;">;</span>
		<span style="color: #0000ff;">for</span><span style="color: #008000;">&#40;</span><span style="color: #0000ff;">int</span> i <span style="color: #000080;">=</span> <span style="color: #0000dd;">0</span><span style="color: #008080;">;</span> i<span style="color: #000080;">&lt;</span>profit.<span style="color: #007788;">size</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>i<span style="color: #000040;">++</span><span style="color: #008000;">&#41;</span>
		<span style="color: #008000;">&#123;</span>
			<span style="color: #0000ff;">if</span><span style="color: #008000;">&#40;</span>profit<span style="color: #008000;">&#91;</span>i<span style="color: #008000;">&#93;</span> <span style="color: #000080;">&gt;</span> maxi<span style="color: #008000;">&#41;</span>
			<span style="color: #008000;">&#123;</span>
				maxi <span style="color: #000080;">=</span> profit<span style="color: #008000;">&#91;</span>i<span style="color: #008000;">&#93;</span><span style="color: #008080;">;</span>
				place <span style="color: #000080;">=</span> i<span style="color: #008080;">;</span>
			<span style="color: #008000;">&#125;</span>
		<span style="color: #008000;">&#125;</span>	
&nbsp;
		<span style="color: #0000ff;">return</span> place<span style="color: #008080;">;</span>
	<span style="color: #008000;">&#125;</span></pre></div></div>

<p>The above function simply returns the index of the max element. It is easy to calculate that this code runs in O(N) time.</p>

<div class="wp_syntax"><div class="code"><pre class="cpp" style="font-family:monospace;"><span style="color: #0000ff;">int</span> min<span style="color: #008000;">&#40;</span>vector<span style="color: #000080;">&lt;</span><span style="color: #0000ff;">int</span><span style="color: #000080;">&gt;</span> profit,<span style="color: #0000ff;">int</span> aa<span style="color: #008000;">&#41;</span>
		<span style="color: #008000;">&#123;</span>
		<span style="color: #0000ff;">int</span> place<span style="color: #000080;">=</span>aa<span style="color: #008080;">;</span>
		<span style="color: #0000ff;">int</span> maxi <span style="color: #000080;">=</span> <span style="color: #0000dd;">10001</span><span style="color: #008080;">;</span>
		<span style="color: #0000ff;">for</span><span style="color: #008000;">&#40;</span><span style="color: #0000ff;">int</span> i <span style="color: #000080;">=</span> <span style="color: #0000dd;">0</span><span style="color: #008080;">;</span> i<span style="color: #000080;">&lt;</span>profit.<span style="color: #007788;">size</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>i<span style="color: #000040;">++</span><span style="color: #008000;">&#41;</span>
		<span style="color: #008000;">&#123;</span>
			<span style="color: #0000ff;">if</span><span style="color: #008000;">&#40;</span>profit<span style="color: #008000;">&#91;</span>i<span style="color: #008000;">&#93;</span> <span style="color: #000080;">&lt;</span> maxi<span style="color: #008000;">&#41;</span>
			<span style="color: #008000;">&#123;</span>
				<span style="color: #0000ff;">if</span><span style="color: #008000;">&#40;</span>i <span style="color: #000040;">!</span><span style="color: #000080;">=</span> aa<span style="color: #008000;">&#41;</span>
				<span style="color: #008000;">&#123;</span>
				maxi <span style="color: #000080;">=</span> profit<span style="color: #008000;">&#91;</span>i<span style="color: #008000;">&#93;</span><span style="color: #008080;">;</span>
				place <span style="color: #000080;">=</span> i<span style="color: #008080;">;</span>
				<span style="color: #008000;">&#125;</span>
			<span style="color: #008000;">&#125;</span>
		<span style="color: #008000;">&#125;</span>	
&nbsp;
		<span style="color: #0000ff;">return</span> place<span style="color: #008080;">;</span>
	<span style="color: #008000;">&#125;</span></pre></div></div>

<p>Well this is the same as findMax function. The only trick is that I pass the index of max profit element in order to ignore it while finding the lowest decay element. Nothing special.</p>
<p>And in the actual function, I simply substract the lowest decay from the highest profit value. The code as a whole looks like this:</p>

<div class="wp_syntax"><div class="code"><pre class="cpp" style="font-family:monospace;"><span style="color: #339900;">#include &lt;vector&gt;</span>
<span style="color: #339900;">#include &lt;set&gt;</span>
<span style="color: #0000ff;">using</span> <span style="color: #0000ff;">namespace</span> std<span style="color: #008080;">;</span>
&nbsp;
<span style="color: #0000ff;">class</span> TimeTravellingCellar
<span style="color: #008000;">&#123;</span>
	<span style="color: #0000ff;">public</span><span style="color: #008080;">:</span>
	<span style="color: #0000ff;">int</span> max<span style="color: #008000;">&#40;</span>vector<span style="color: #000080;">&lt;</span><span style="color: #0000ff;">int</span><span style="color: #000080;">&gt;</span> profit<span style="color: #008000;">&#41;</span>
	<span style="color: #008000;">&#123;</span>
		<span style="color: #0000ff;">int</span> place<span style="color: #000080;">=</span><span style="color: #0000dd;">0</span><span style="color: #008080;">;</span>
		<span style="color: #0000ff;">int</span> maxi <span style="color: #000080;">=</span> <span style="color: #0000dd;">0</span><span style="color: #008080;">;</span>
		<span style="color: #0000ff;">for</span><span style="color: #008000;">&#40;</span><span style="color: #0000ff;">int</span> i <span style="color: #000080;">=</span> <span style="color: #0000dd;">0</span><span style="color: #008080;">;</span> i<span style="color: #000080;">&lt;</span>profit.<span style="color: #007788;">size</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>i<span style="color: #000040;">++</span><span style="color: #008000;">&#41;</span>
		<span style="color: #008000;">&#123;</span>
			<span style="color: #0000ff;">if</span><span style="color: #008000;">&#40;</span>profit<span style="color: #008000;">&#91;</span>i<span style="color: #008000;">&#93;</span> <span style="color: #000080;">&gt;</span> maxi<span style="color: #008000;">&#41;</span>
			<span style="color: #008000;">&#123;</span>
				maxi <span style="color: #000080;">=</span> profit<span style="color: #008000;">&#91;</span>i<span style="color: #008000;">&#93;</span><span style="color: #008080;">;</span>
				place <span style="color: #000080;">=</span> i<span style="color: #008080;">;</span>
			<span style="color: #008000;">&#125;</span>
		<span style="color: #008000;">&#125;</span>	
&nbsp;
		<span style="color: #0000ff;">return</span> place<span style="color: #008080;">;</span>
	<span style="color: #008000;">&#125;</span>
&nbsp;
	<span style="color: #0000ff;">int</span> min<span style="color: #008000;">&#40;</span>vector<span style="color: #000080;">&lt;</span><span style="color: #0000ff;">int</span><span style="color: #000080;">&gt;</span> profit,<span style="color: #0000ff;">int</span> aa<span style="color: #008000;">&#41;</span>
		<span style="color: #008000;">&#123;</span>
		<span style="color: #0000ff;">int</span> place<span style="color: #000080;">=</span>aa<span style="color: #008080;">;</span>
		<span style="color: #0000ff;">int</span> maxi <span style="color: #000080;">=</span> <span style="color: #0000dd;">10001</span><span style="color: #008080;">;</span>
		<span style="color: #0000ff;">for</span><span style="color: #008000;">&#40;</span><span style="color: #0000ff;">int</span> i <span style="color: #000080;">=</span> <span style="color: #0000dd;">0</span><span style="color: #008080;">;</span> i<span style="color: #000080;">&lt;</span>profit.<span style="color: #007788;">size</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>i<span style="color: #000040;">++</span><span style="color: #008000;">&#41;</span>
		<span style="color: #008000;">&#123;</span>
			<span style="color: #0000ff;">if</span><span style="color: #008000;">&#40;</span>profit<span style="color: #008000;">&#91;</span>i<span style="color: #008000;">&#93;</span> <span style="color: #000080;">&lt;</span> maxi<span style="color: #008000;">&#41;</span>
			<span style="color: #008000;">&#123;</span>
				<span style="color: #0000ff;">if</span><span style="color: #008000;">&#40;</span>i <span style="color: #000040;">!</span><span style="color: #000080;">=</span> aa<span style="color: #008000;">&#41;</span>
				<span style="color: #008000;">&#123;</span>
				maxi <span style="color: #000080;">=</span> profit<span style="color: #008000;">&#91;</span>i<span style="color: #008000;">&#93;</span><span style="color: #008080;">;</span>
				place <span style="color: #000080;">=</span> i<span style="color: #008080;">;</span>
				<span style="color: #008000;">&#125;</span>
			<span style="color: #008000;">&#125;</span>
		<span style="color: #008000;">&#125;</span>	
&nbsp;
		<span style="color: #0000ff;">return</span> place<span style="color: #008080;">;</span>
	<span style="color: #008000;">&#125;</span>
&nbsp;
	<span style="color: #0000ff;">int</span> determineProfit<span style="color: #008000;">&#40;</span>vector<span style="color: #000080;">&lt;</span><span style="color: #0000ff;">int</span><span style="color: #000080;">&gt;</span> profit, vector<span style="color: #000080;">&lt;</span><span style="color: #0000ff;">int</span><span style="color: #000080;">&gt;</span> decay<span style="color: #008000;">&#41;</span>
	<span style="color: #008000;">&#123;</span>
		<span style="color: #0000ff;">int</span> maxi <span style="color: #000080;">=</span> max<span style="color: #008000;">&#40;</span>profit<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
		<span style="color: #0000ff;">int</span> mini <span style="color: #000080;">=</span> min<span style="color: #008000;">&#40;</span>decay,maxi<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
&nbsp;
		<span style="color: #0000ff;">return</span> profit<span style="color: #008000;">&#91;</span>maxi<span style="color: #008000;">&#93;</span> <span style="color: #000040;">-</span> decay<span style="color: #008000;">&#91;</span>mini<span style="color: #008000;">&#93;</span><span style="color: #008080;">;</span>
	<span style="color: #008000;">&#125;</span>
<span style="color: #008000;">&#125;</span><span style="color: #008080;">;</span></pre></div></div>

<p>After submitting the solution, I have found a bug in my program. Consider the situation: profit = { 888, 889, 100 }, decay = { 100, 1, 97 }. Let&#8217;s simulate what my program will do: It will find position of max element which is 889, then it will find position of min element. However, while finding the min element, it will return 97 due to ignoring second cellar. Finally it will return the answer as 889 &#8211; 97. However, this is not the best situation. The best profit we can get is 888 &#8211; 1. This situation happens when the lowest decay and highest profit is at the same cellar. This bug can be easily solved by a if statement, so I will not correct it now.</p>
<p>As you see, even the easiest problems can contain painful corner cases. If you find a bug in my solution, feel free to inform me. </p>
<p>PS: Sorry for the bad indentation. WP and Copy-Paste are responsible for this!</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.ayberkyilmaz.net/2011/topcoder-srm-492-timetravellingcellar-c-163/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>ADTs : Stacks</title>
		<link>http://blog.ayberkyilmaz.net/2010/adts-stacks-140</link>
		<comments>http://blog.ayberkyilmaz.net/2010/adts-stacks-140#comments</comments>
		<pubDate>Fri, 22 Oct 2010 20:35:27 +0000</pubDate>
		<dc:creator>Ayberk Yılmaz</dc:creator>
				<category><![CDATA[Teknik]]></category>
		<category><![CDATA[c]]></category>
		<category><![CDATA[data structures]]></category>
		<category><![CDATA[stack]]></category>

		<guid isPermaLink="false">http://blog.ayberkyilmaz.net/?p=140</guid>
		<description><![CDATA[As an exercise, i will design and implement my own stack ADT. First of all we need to build necessary structures. The Head structure will contain a counter and a pointer to stack nodes. The node structure will contain a data pointer and a node pointer. typedef struct node2 &#123; void *dataPtr; struct node2 *nodePtr; [...]]]></description>
			<content:encoded><![CDATA[<p>As an exercise, i will design and implement my own stack ADT.</p>
<p>First of all we need to build necessary structures.</p>
<p>The Head structure will contain a counter and a pointer to stack nodes.</p>
<p>The node structure will contain a data pointer and a node pointer.</p>

<div class="wp_syntax"><div class="code"><pre class="c" style="font-family:monospace;"><span style="color: #993333;">typedef</span> <span style="color: #993333;">struct</span> node2
<span style="color: #009900;">&#123;</span>
   <span style="color: #993333;">void</span> <span style="color: #339933;">*</span>dataPtr<span style="color: #339933;">;</span>
   <span style="color: #993333;">struct</span> node2 <span style="color: #339933;">*</span>nodePtr<span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span> NODE<span style="color: #339933;">;</span>
&nbsp;
<span style="color: #993333;">typedef</span> <span style="color: #993333;">struct</span>
<span style="color: #009900;">&#123;</span>
   <span style="color: #993333;">int</span> count<span style="color: #339933;">;</span>
   NODE <span style="color: #339933;">*</span>top<span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span> STACK<span style="color: #339933;">;</span></pre></div></div>

<p>We have constructed two structures: STACK structure will be the head of the stack. The head structure has a NODE pointer to the top of the stack and an integer to hold the number of the nodes. NODE structure will hold the given data. And of course, it has a link to another node.</p>
<p>Since we have constructed the structures, we can start to implement the operations.</p>
<p>Let me talk about the operations that i will implement. I am going to implement create, push and pop operations. Push adds data to the stack and pop retrieves data. As you know, all the operations affect the top of the stack.</p>
<p>In order to create a stack, we need to allocate the necessary memory and then we must update the head node:</p>

<div class="wp_syntax"><div class="code"><pre class="c" style="font-family:monospace;">STACK <span style="color: #339933;">*</span>createStack<span style="color: #009900;">&#40;</span><span style="color: #993333;">void</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
   STACK<span style="color: #339933;">*</span> stack<span style="color: #339933;">;</span>
&nbsp;
   stack <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>STACK<span style="color: #339933;">*</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#40;</span>malloc<span style="color: #009900;">&#40;</span><span style="color: #993333;">sizeof</span><span style="color: #009900;">&#40;</span>STACK<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
   <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span>stack<span style="color: #009900;">&#41;</span>
   <span style="color: #009900;">&#123;</span>
      stack<span style="color: #339933;">-&gt;</span>count <span style="color: #339933;">=</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">;</span>
      stack<span style="color: #339933;">-&gt;</span>top <span style="color: #339933;">=</span> NULL<span style="color: #339933;">;</span>
   <span style="color: #009900;">&#125;</span>
&nbsp;
   <span style="color: #b1b100;">return</span> stack<span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>This one is easy to explain. We simply allocate memory for the head node and if allocation is done successfully, we simply set the counter as zero and pointer as NULL due to having no items at the stack.</p>
<p>After successfully creating the stack, the next goal is adding data to the stack. It is a little bit more trivial but still easy to understand. I will not explain the code, not now at least.</p>

<div class="wp_syntax"><div class="code"><pre class="c" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">// it will return 1 if the operation is successful, 0 otherwise</span>
<span style="color: #666666; font-style: italic;">// thanks to the generic pointer, any type of data can be pushed</span>
<span style="color: #993333;">int</span> pushStack<span style="color: #009900;">&#40;</span>STACK<span style="color: #339933;">*</span> stack<span style="color: #339933;">,</span> <span style="color: #993333;">void</span><span style="color: #339933;">*</span> data<span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
    <span style="color: #666666; font-style: italic;">// allocate memory for the new node</span>
    NODE<span style="color: #339933;">*</span> node<span style="color: #339933;">;</span>
    node <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>NODE<span style="color: #339933;">*</span><span style="color: #009900;">&#41;</span>malloc<span style="color: #009900;">&#40;</span><span style="color: #993333;">sizeof</span><span style="color: #009900;">&#40;</span>NODE<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #666666; font-style: italic;">// check if allocations is done</span>
    <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span>node<span style="color: #009900;">&#41;</span>
       <span style="color: #b1b100;">return</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">;</span>   
&nbsp;
   <span style="color: #666666; font-style: italic;">// update the node</span>
   node<span style="color: #339933;">-&gt;</span>nodePtr <span style="color: #339933;">=</span> stack<span style="color: #339933;">-&amp;</span>gt<span style="color: #339933;">;</span>top<span style="color: #339933;">;</span>
   node<span style="color: #339933;">-&gt;</span>dataPtr <span style="color: #339933;">=</span> data<span style="color: #339933;">;</span>
&nbsp;
   <span style="color: #666666; font-style: italic;">// update the head</span>
   stack<span style="color: #339933;">-&gt;</span>top <span style="color: #339933;">=</span> node<span style="color: #339933;">;</span>
   <span style="color: #009900;">&#40;</span>stack<span style="color: #339933;">-&gt;</span>count<span style="color: #009900;">&#41;</span><span style="color: #339933;">++;</span>
&nbsp;
   <span style="color: #b1b100;">return</span> <span style="color: #0000dd;">1</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Now it is time to retrieve data.</p>

<div class="wp_syntax"><div class="code"><pre class="c" style="font-family:monospace;"><span style="color: #993333;">void</span> <span style="color: #339933;">*</span>popStack<span style="color: #009900;">&#40;</span>STACK<span style="color: #339933;">*</span> stack<span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
    <span style="color: #993333;">void</span> <span style="color: #339933;">*</span>dataOut<span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">//again, we love you generic pointer</span>
&nbsp;
   <span style="color: #666666; font-style: italic;">// empty stack cannot be popped</span>
   <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span>stack<span style="color: #339933;">-&gt;</span>count<span style="color: #339933;">==</span><span style="color: #0000dd;">0</span><span style="color: #009900;">&#41;</span>
     dataOut <span style="color: #339933;">=</span> NULL<span style="color: #339933;">;</span>
   <span style="color: #b1b100;">else</span>
   <span style="color: #009900;">&#123;</span>
      dataOut <span style="color: #339933;">=</span> stack<span style="color: #339933;">-&gt;</span>head<span style="color: #339933;">-&gt;</span>dataPtr<span style="color: #339933;">;</span>
      NODE<span style="color: #339933;">*</span> temp <span style="color: #339933;">=</span> stack<span style="color: #339933;">-&gt;</span>top<span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// we dont want no leaks</span>
      stack<span style="color: #339933;">-&amp;</span>gt<span style="color: #339933;">;</span>top <span style="color: #339933;">=</span> stack<span style="color: #339933;">-&gt;</span>top<span style="color: #339933;">&gt;</span>nodePtr<span style="color: #339933;">;</span>
      <span style="color: #009900;">&#40;</span>stack<span style="color: #339933;">-&gt;</span>count<span style="color: #009900;">&#41;</span><span style="color: #339933;">--;</span>
      free<span style="color: #009900;">&#40;</span>temp<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// freedom &lt;3</span>
   <span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #b1b100;">return</span> dataOut<span style="color: #339933;">;</span> 
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>I know i have not explained neither the code nor the ADT itself well enough. I will try to update this post -most probably i will not- but the whole point of this post is implementing stacks on my own and recapping it. </p>
<p>I have written all the code on wordpress and have not compiled. If you try any errors or if you have any questions, please feel free to ask or inform me. </p>
]]></content:encoded>
			<wfw:commentRss>http://blog.ayberkyilmaz.net/2010/adts-stacks-140/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Char to Int Conversion in C</title>
		<link>http://blog.ayberkyilmaz.net/2010/char-to-int-conversion-in-c-101</link>
		<comments>http://blog.ayberkyilmaz.net/2010/char-to-int-conversion-in-c-101#comments</comments>
		<pubDate>Thu, 01 Jul 2010 21:01:44 +0000</pubDate>
		<dc:creator>Ayberk Yılmaz</dc:creator>
				<category><![CDATA[Teknik]]></category>
		<category><![CDATA[c]]></category>
		<category><![CDATA[char to int]]></category>
		<category><![CDATA[char to int conversion]]></category>

		<guid isPermaLink="false">http://blog.ayberkyilmaz.net/?p=101</guid>
		<description><![CDATA[The programming thing has a lot of tricks and as a programmer, I like them very very much. The latest trick that i have come across is converting a char digit to its integer value. As you know, if you write something like this: char num[11] = "0123456789"; int s = (int)num[0]; printf("%d\n",s); It will [...]]]></description>
			<content:encoded><![CDATA[<p>The programming thing has a lot of tricks and as a programmer, I like them very very much.</p>
<p>The latest trick that i have come across is converting a char digit to its integer value.</p>
<p>As you know, if you write something like this:</p>
<p><code>char num[11] = "0123456789";<br />
int s = (int)num[0];<br />
printf("%d\n",s);</code></p>
<p>It will not print 0, but instead it will print the <a href="http://www.asciitable.com">ASCII</a> value of &#8217;0&#8242;.</p>
<p>While looking for a quick solution, I have seen this perfect trick at stackoverflow:</p>
<p><code>char num[11] = "0123456789";<br />
int s = num[0] - '0';<br />
printf("%d\n",s);</code></p>
<p>Since all the digits are consecutive at the ASCII Table, -supposing all the elements are digits- substracting the ASCII value of &#8217;0&#8242; from that digit&#8217;s ASCII value gives you the correct integer value of the digit.</p>
<p>All that I can say is: FASCINATING!</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.ayberkyilmaz.net/2010/char-to-int-conversion-in-c-101/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>How to Get Noticed by Google</title>
		<link>http://blog.ayberkyilmaz.net/2010/how-to-get-noticed-by-google-81</link>
		<comments>http://blog.ayberkyilmaz.net/2010/how-to-get-noticed-by-google-81#comments</comments>
		<pubDate>Fri, 07 May 2010 17:16:32 +0000</pubDate>
		<dc:creator>Ayberk Yılmaz</dc:creator>
				<category><![CDATA[Teknik]]></category>
		<category><![CDATA[google]]></category>
		<category><![CDATA[interview]]></category>
		<category><![CDATA[open source projects]]></category>

		<guid isPermaLink="false">http://blog.ayberkyilmaz.net/?p=81</guid>
		<description><![CDATA[Self explaining headline explaines it all. Two engineers from google answer the question. httpv://www.youtube.com/watch?v=E2dMmdewRxE]]></description>
			<content:encoded><![CDATA[<p>Self explaining headline explaines it all.</p>
<p>Two engineers from google answer the question.</p>
<p><a href="http://www.youtube.com/watch?v=E2dMmdewRxE">httpv://www.youtube.com/watch?v=E2dMmdewRxE</a></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.ayberkyilmaz.net/2010/how-to-get-noticed-by-google-81/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Linux&#8217;ta Komut Penceresi, Konsol ve Ona Benzer Şeyler Hadisesi</title>
		<link>http://blog.ayberkyilmaz.net/2010/linuxta-komut-penceresi-konsol-ve-ona-benzer-seyler-adisesi-77</link>
		<comments>http://blog.ayberkyilmaz.net/2010/linuxta-komut-penceresi-konsol-ve-ona-benzer-seyler-adisesi-77#comments</comments>
		<pubDate>Fri, 07 May 2010 15:13:25 +0000</pubDate>
		<dc:creator>Ayberk Yılmaz</dc:creator>
				<category><![CDATA[Teknik]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[shell]]></category>

		<guid isPermaLink="false">http://blog.ayberkyilmaz.net/?p=77</guid>
		<description><![CDATA[Cok uzun zamandir aklimda olup da, buraya koymaya bir turlu firsat bulamadigim bir yaziyi koymak istiyorum. Yazi gercekten cok ama cok guzel. Konusu ise kisaca isletim sistemlerini cok guzel bir benzetme kullanarak karsilastirirken linuxtaki konsolun yararlarini anlatmak. Bu orijinal yazinin sahibi ozgurlukicin forumundan &#8220;mu1&#8243;. Yazinin orijinaline surdan ulasabilirsiniz: http://www.ozgurlukicin.com/forum/nasil/13894/?page=1 Linux kullanmaya Windows&#8217;tan geçenlerin en canını [...]]]></description>
			<content:encoded><![CDATA[<p>Cok uzun zamandir aklimda olup da, buraya koymaya bir turlu firsat bulamadigim bir yaziyi koymak istiyorum. Yazi gercekten cok ama cok guzel. Konusu ise kisaca isletim sistemlerini cok guzel bir benzetme kullanarak karsilastirirken linuxtaki konsolun yararlarini anlatmak.</p>
<p>Bu orijinal yazinin sahibi ozgurlukicin forumundan &#8220;mu1&#8243;. Yazinin orijinaline surdan ulasabilirsiniz: <a href="http://www.ozgurlukicin.com/forum/nasil/13894/?page=1">http://www.ozgurlukicin.com/forum/nasil/13894/?page=1</a></p>
<blockquote><p>Linux kullanmaya Windows&#8217;tan geçenlerin en canını sıkan şeylerden birisi, ikide bir komut penceresi ve ille de Konsol diye bir şey kullanma gereksinimidir. Oraya buraya tıklayıp işini görmek dururken ilkel görünüşlü bir şeye karışık ve anlamsız şeyler yazmak, sistemin yazdıklarını beğenmemesi, çoğu komutun sonunda sistemin hiç bir şey söylemeden öylece beklemesi gibi şeyler canlarını sıkar. Arada bir “buna yetkiniz yok, root diye bir şey olmanız gerekiyor, ama root olmak ta hiç iyi bişi değildir” türü uyarılar da alınca iyice ayar olurlar. Hele ki bir Linux ortamında zor bela alıştıkları komutlar var da onları bir diğerinde bulamazlarsa hepten gına gelir. Nedir bu çile?</p>
<p>Şimdi, konsolu filan bir tarafa bırakıp, yemeğe gittiğimizi varsayalım.</p>
<p>Diyelim ki amatör aşçıyız ve bol yıldızlı bir otelin restoranına müşteri olarak gittik. Girdiğimiz yerde şık bir dekorasyon, jilet gibi düzenlenmiş masalar, kibar garsonlar ve ışıltılı bir atmosfer olacaktır. Yemeğimizi sipariş ettik ve geldi. Baktık ki yemek iyi hoş olmuş, sunum güzel, lezzeti de fena değil ama yine de tam istediğimiz gibi değil. Örneğin, biz yemekteki soğanı standart haliyle değil de başka şekilde hazırlansın istiyoruz. İşi de biliyoruz ya, tutturduk aşçıyla konuşacağız diye.</p>
<p>Bu restoranda, garsonu yemekten anladığımıza ikna edebilirsek bizi şefle görüştürmeye yanaşır ve bizi mutfağa alır. Mutfağa girince de iki şey olur.</p>
<p>Önce ortamın değiştiğini farkederiz. Burada süslü masalar ve yumuşak ışıklandırma yerine, belli bir düzende koşuşturan personel, sıraya sokulmuş malzeme, yıkama, pişirme vs. aletleri ve endüstriyel ışıklandırma görürüz. Çünkü burada amaç hızla yemek hazırlamak, aynı anda birkaç siparişin hazırlanıp aksamadan masalara gitmesini sağlamak, artıkları hızla yok etmek ve malzeme firesini en azda tutmaktır, işin süs kısmı dışarıdadır. Aşçılar birbirleriyle konuşurken kısa cümleler ve yanlış anlamaya olanak vermeyen bir mesleki terminoloji kullanırlar. Dışarıdan bakan biri yemek mi hazırlıyorlar cepheye mühimmat mı hazırlıyorlar anlamayabilir.</p>
<p>Mutfağa girdiğimizde olan ikinci şey, çalışanların bize “hoop hemşerim, sen müşterisin buraya girmemen lazım, bişey devirip elini filan yakarsın burda, derdin ne?” bakışıyla bize bakmasıdır. Biz de usulünce (yetkili kullanıcı şifresi girerek) sıradan müşteri olmadığımızı, yemek işinden anladığımızı, ortalığı dağıtmaya gelmediğimizi, yemeğin sunulan halinden başka ilave şeyler de istediğimizi izah ederiz. İçeride bir şeyler devirip yangın çıkarmayacağımıza (yetkili kullanıcıyız ya) ikna oldukları zaman, bizi yemeği yapan aşçıyla görüştürmeye razı olurlar.</p>
<p>Aşçıyla konuşurken, onun mesleki dilden konuşmamız gerekir, yoksa ince ayrıntılarda anlaşamayabiliriz. Neyse ki biz de aşçıyız ve dil konusunda bir sorunumuz yok. İstediğimiz standart dışı değişikliği en ince ayrıntısına kadar tarif edip tam olarak tanımlayabiliriz.</p>
<p>Bazı durumlarda, “bu tatlıya altın tozu da serpin, bu mantarlar yerine de Vezüv dağı eteklerinde yetişen şu türden mantarları kullanın” gibi enteresan isteklerimiz olur. O zaman da bize “biz o kadarını bilmeyiz, şef bilir” derler. Şef meşgul bir kişidir, onunla öyle her babayiğit konuşamaz. (onunla konuşmak için &#8216;root&#8217; şifresi gerekir). Eğer bu engeli de aşarsak, o zaman şefe derdimizi anlatıp, fırın ve ocakların ısısıyla filan da oynayıp iyice standart dışı, ama tastamam istediğimiz gibi bir yemek hazırlatabiliriz.</p>
<p>Bütün bunları restoran kısmındaki şık giyimli garsonla süslü masamızdan konuşarak yapamayız.</p>
<p>Eğer bu otelin adı Linux oteli ise, hesabı istediğimiz zaman bizden para pul da almazlar, bu da işi birazcık bilmenin faydasıdır. Bu restoranın hoş bir özelliği de hazır menü dışında, açık büfesinin de olmasıdır. Eğer aşçılıktan az biraz anlıyorsak, oradaki malzemelerden seçip keyfimize göre pişirtebiliriz, ona da para almazlar.</p>
<p>Şimdi bir de, başka bir otelin restoranına bakalım. Bunun adı da Windoze oteller zinciri olsun. Burada da restoran bölümü çok şık, garsonlar şık ve kibar, ortam güzel, ambiyans ta iyi.</p>
<p>Ama bu zincire ait restoranların birkaç farkı var. Öncelikle, yiyip içeceğimizin parasını peşin alıyorlar, karşılığında da yediklerimizi beğenmezsek garsonlar koşuşturup bizi memnun edene kadar uğraşacaklarını taahhüt ediyorlar. Şehrin her tarafında bu restoranlardan var, üstelik taklitleri de çok. Ancak taklit restorana bir kere gitmişsek, yediğimizden zehirlensek bile bir şey yapmıyorlar. Böyle bir durumda asıl restoran da bizi umursamıyor. Yemek tariflerini sır gibi saklıyorlar ve kullandıkları malzemeyi de söylemiyorlar. Adamlar haklı, pahalı bir yatırım yapmışlar ve masrafı çıkarmak zorundalar. Şehirde adım başı bu restoranlardan olduğu için de herkes orayı biliyor ve gidip bir şeyler yiyor. Her şeye rağmen iyi kazanıyorlar yani.</p>
<p>Bu restoranın başka bir özelliği, profesyonel aşçı bile olsak, eninde sonunda müşteri olduğumuz için bizi hiç mutfağa sokmamaları. Her şeyi restoran kısmında garsonlarla halletmek zorundayız. Çok çok, mutfaklarında bir ön büro var, eğer bilinçli müşteri olduğumuza inanırlarsa (administrator kartvizitimiz varsa) oraya alıp derdimizi dinliyorlar. Ama ön büroda yapabileceklerimiz çok sınırlı, derdimizi ayrıntısıyla anlatabileceğimiz, anlatmak istesek te bizi anlayabilecek eleman yok. Zaten bu restoran zinciri, profesyonel aşçıları değil, sadece konforlu bir ortamda menüde ne varsa onu yemek isteyen müşterileri hedef kitle olarak benimsemiş. Servis çok ağır da olsa rahatlığı ön planda tutan müşteriler bundan pek yakınmıyor.</p>
<p>Bu restoranın diğer bir özelliği de, “nasıl olsa bize profesyonel aşçılar yemek yemeğe gelmiyor” diye hijyen ve korumaya pek önem vermemesi. Parası olan herkes girsin diye de her tarafında kapı ve ardına kadar açık pencereler var. Bu yüzden yemek işinden biraz anlayan kötü niyetliler zaman zaman içeri dalıp malzemeye zehirli maddeler katabiliyor. Yapısal güvenlik önceden düşünülmediği için de restoranın buna karşı tek önlemi, yabancı daha önce hangi kapıdan girmişse o kapıyı kapatmak, ya da bozulma olasılığı olan yemeği menüden çıkartmak. Bu çoğu zaman müşterilere de zorluk yaratıyor, ama yapılabilecek başka bir şey yok. İsteyen müşteri parayla özel güvenlik elemanı tutabiliyor, ama bu da servisi iyice yavaşlatıyor.</p>
<p>Bu zincirin bir başka sorunu da, en baştan tasarlanırken çok hafif malzemeli yemekler için düşünülmüş olması. Gerçi şimdilerde mutfak inşaatları çok daha sağlam, ama eski yemek tariflerine uyumlu olması için bugün de binaların bazı yerleri birçok zayıflık içeriyor maalesef. Bu yüzden, dışarıdan gelen haydutlar sadece yemekleri zehirlemekle kalmayıp bazen restoranın binasını da çökertebiliyor. O durumlarda çözüm, mutfağı yıkıp yeniden yapmaya kadar gidebiliyor.</p>
<p>Kısacası, Windoze otellerinin restoranlarında işler yolunda gittiği, kimse yemekleri zehirlemeye kalkmadığı, teröristler veya sakar müşteriler binayı çökertmediği ve parayı peşin ödediğimiz sürece şık ve konforlu bir ortamda oturup menüde ne varsa alıp rahat rahat yiyebiliyoruz. Menüde de iyili kötülü pek çok seçenek var, müşterilerin çoğunluğu da bunları yeterli bulup fazlasını istemiyor. Eğer biz fazlasını istersek, sadece nasihat alıyoruz.</p>
<p>Bunların yanında bir de, Mack OZX adlı bir otel zinciri daha var. Burası mimari olarak Linux otelleriyle çok benzeşiyor, ancak müşterisine Windoze otellerinin restoranlarındaki konforu yaşatmaya çalışıyor. Üstelik garson olarak ta seksi görünümlü hanımlar var. Burada, eğer uzman aşçıysanız yine mutfağa girip şefle konuşma şansınız var. Ama bu o kadar fazla gerekmiyor, çünkü buradaki garsonlar Windoze zincirindekinden çok daha becerikli, yemekler konusunda pek çok özel talebimizi leb demeden leblebiyi anlayıp karşılayabiliyorlar. Ama bu restoran oldukça lüks ve pahalı. Kulüp gibi bir fiyatlandırma anlayışları da var; ilk giriş pahalı, sonrası &#8216;ehven&#8217;. Ama çok şık bir yer olduğu için her gidişte başka bir kıyafet giyilmesi gerekiyor, bu da uzun dönemli maliyeti etkiliyor tabii. Zengin işi kısacası&#8230;</p>
<p>Şimdi gerçek dünyaya geri dönersek, Linux&#8217;daki Konsol emulatörü (veya alışılmış dille komut penceresi) istediğimiz yemeği tam ve eksiksiz olarak ilgilisine tarif edebilmek için girdiğimiz mutfak bölümüdür. Gerçi mutfağa kadar zahmet etmeden de oturduğumuz şık ve rahat masadan kolayca garsona siparişimizi verebiliriz. Ama o zaman menüde ne varsa onlardan birini seçmek ve orada nasıl yapılıyorsa öyle yemek zorundayızdır.</p>
<p>Eğer bir problem yüzünden restoran bölümünü o gün açamamışlarsa, o takdirde otelin arka kapısından geçip mutfağa doğrudan gireriz. Bu arka kapı da sistem konsolu oluyor.</p>
<p>Kısacası, Linux&#8217;taki o çirkin görünümlü, zahmetli konsol ve konsol emulatörleri, bize diğer işletim sistemlerinin veremediği esneklik ve sistem kalbine uzanma olanağını sağlıyor. Onların konuştuğu dili birazcık öğrenirsek bize çok çok fazla ek olanak tanırlar. Bu yüzden onları sevelim, itip kakmayalım. Bir gün lazım olabilirler.</p></blockquote>
]]></content:encoded>
			<wfw:commentRss>http://blog.ayberkyilmaz.net/2010/linuxta-komut-penceresi-konsol-ve-ona-benzer-seyler-adisesi-77/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>

