<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:blogger='http://schemas.google.com/blogger/2008' xmlns:georss='http://www.georss.org/georss' xmlns:gd="http://schemas.google.com/g/2005" xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-977483438624583257</id><updated>2024-09-12T22:33:09.621-07:00</updated><category term="Linked List"/><category term="Linked list reverse"/><category term="c++"/><title type='text'>AlgoPadawan</title><subtitle type='html'>Consolidating random fun coding problems from novice level to the more advanced with links to the tutorials for the same.</subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://algopadawan.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/977483438624583257/posts/default?redirect=false'/><link rel='alternate' type='text/html' href='http://algopadawan.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/10176620256158287366</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>5</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>25</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-977483438624583257.post-6700188500465445476</id><published>2012-08-26T10:06:00.001-07:00</published><updated>2012-08-26T10:06:09.213-07:00</updated><title type='text'>Gen Y work place infographic</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiDQaJq07FVxJgeRdXZO64nNS2mnxbi500k28NQBLWzl72LQYVUqGnhF4i5l7TMu9r6YSvpgXALoeut989ezHp5eiMr0VUO-czqDBHJNVju7rPn5_yy4uvSJ-ALx9lLGhUAjBRXV5ZqIuJo/s1600/ps_geny_final_890a.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiDQaJq07FVxJgeRdXZO64nNS2mnxbi500k28NQBLWzl72LQYVUqGnhF4i5l7TMu9r6YSvpgXALoeut989ezHp5eiMr0VUO-czqDBHJNVju7rPn5_yy4uvSJ-ALx9lLGhUAjBRXV5ZqIuJo/s1600/ps_geny_final_890a.png&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;span style=&quot;font-family: Helvetica Neue, Arial, Helvetica, sans-serif;&quot;&gt;from(http://www.payscale.com/gen-y-at-work)&lt;/span&gt;&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://algopadawan.blogspot.com/feeds/6700188500465445476/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://algopadawan.blogspot.com/2012/08/gen-y-work-place-infographic.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/977483438624583257/posts/default/6700188500465445476'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/977483438624583257/posts/default/6700188500465445476'/><link rel='alternate' type='text/html' href='http://algopadawan.blogspot.com/2012/08/gen-y-work-place-infographic.html' title='Gen Y work place infographic'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/10176620256158287366</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiDQaJq07FVxJgeRdXZO64nNS2mnxbi500k28NQBLWzl72LQYVUqGnhF4i5l7TMu9r6YSvpgXALoeut989ezHp5eiMr0VUO-czqDBHJNVju7rPn5_yy4uvSJ-ALx9lLGhUAjBRXV5ZqIuJo/s72-c/ps_geny_final_890a.png" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-977483438624583257.post-4628534085874344203</id><published>2012-07-20T16:15:00.001-07:00</published><updated>2012-07-20T16:15:19.382-07:00</updated><title type='text'>Installing OpenGrok on Windows</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;br /&gt;
&lt;h2&gt;










&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;Installing OpenGrok on Windows&lt;/span&gt;&lt;/h2&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; font-family: Verdana, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; font-family: Verdana, sans-serif;&quot;&gt;Steps for installing OpenGrok.&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;ol style=&quot;text-align: left;&quot;&gt;
&lt;li&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;Download the OpenGrok binary from&amp;nbsp;&lt;a href=&quot;http://hub.opensolaris.org/bin/view/Project+opengrok/files&quot; target=&quot;_blank&quot;&gt;OpenGrok Binary&lt;/a&gt;.&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;Unzip the tar to a location say &quot;G:\OpenGrok&quot;&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;Download &lt;a href=&quot;http://ctags.sourceforge.net/&quot; target=&quot;_blank&quot;&gt;Ctags &lt;/a&gt;from&amp;nbsp;&lt;a href=&quot;http://ctags.sourceforge.net/&quot; target=&quot;_blank&quot;&gt;Ctags Windows Binary&lt;/a&gt;.&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;Extract Ctags to a location say &quot;G:\Ctags&quot;&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;Download and install &lt;a href=&quot;http://tomcat.apache.org/download-70.cgi&quot; target=&quot;_blank&quot;&gt;Tomcat&lt;/a&gt;.&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span style=&quot;background-color: white; font-family: Verdana, sans-serif;&quot;&gt;OpenGrok needs the following to run&lt;/span&gt;&lt;/li&gt;
&lt;ol&gt;
&lt;li&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;A configuration.xml that is generated using the command in step 8.&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;Location to the source being indexed. (SRC_ROOT)&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;Location to the &quot;Ctag&quot; generated grokData, again refer to step 8.&amp;nbsp;&lt;/span&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;(DATA_ROOT)&lt;/span&gt;&lt;/li&gt;
&lt;/ol&gt;
&lt;li&gt;&lt;span style=&quot;background-color: white; font-family: Verdana, sans-serif;&quot;&gt;Extract the &quot;war&quot; file in the &quot;lib&quot; folder in the extracted OpenGrok location. In this case &amp;nbsp;G:\opengrok-0.11.1\lib.&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;Edit the WEB-INF\web.xml file to include the information discussed above (step 6)&lt;/span&gt;&lt;/li&gt;
&lt;pre class=&quot;prettyprint&quot; style=&quot;background-color: #f0f0f0; background-position: initial initial; background-repeat: initial initial; border: 1px dashed rgb(204, 204, 204); color: black; font-family: arial; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;&quot;&gt;&lt;code style=&quot;color: black; word-wrap: normal;&quot;&gt; &amp;lt;context-param&amp;gt;  
   &amp;lt;param-name&amp;gt;CONFIGURATION&amp;lt;/param-name&amp;gt;  
   &amp;lt;param-value&amp;gt;G:\opengrok-0.11.1\configuration.xml&amp;lt;/param-value&amp;gt;  
   &amp;lt;description&amp;gt;Full path to the configuration file where OpenGrok can read it&#39;s configuration&amp;lt;/description&amp;gt;  
  &amp;lt;/context-param&amp;gt;  
  -------Added the below------  
  &amp;lt;context-param&amp;gt;    
   &amp;lt;param-name&amp;gt;SRC_ROOT&amp;lt;/param-name&amp;gt;  
   &amp;lt;param-value&amp;gt;G:\CodeSource&amp;lt;/param-value&amp;gt;  
  &amp;lt;/context-param&amp;gt;  
  &amp;lt;context-param&amp;gt;  
   &amp;lt;param-name&amp;gt;DATA_ROOT&amp;lt;/param-name&amp;gt;  
   &amp;lt;param-value&amp;gt;G:\opengrok-0.11.1\grokdata&amp;lt;/param-value&amp;gt;    
  &amp;lt;/context-param&amp;gt;  
&lt;/code&gt;&lt;/pre&gt;
&lt;li&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;Copy the the extracted source.war with the modified web.xml to the tomcat webapps folder.&amp;nbsp;&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;Index the source and generate the configuration.xml file using the below command (G:\opengrok-0.11.1\lib has the jar file)&lt;/span&gt;&lt;/li&gt;
&lt;pre style=&quot;background-image: URL(https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgfh15eeZBA4o4EB73NoevMo2UJQxwddVlccc_EU69lOga_Ian8fjotkUXC5p43x37S5nWXkfMSgh6Tqhj-IpVbEAO-3dueqVTsWLCJAdG-EdM-BKDDyix9IMdKb07RJ5en-wWJyqz-sG33/s320/codebg.gif); background: #f0f0f0; border: 1px dashed #CCCCCC; color: black; font-family: arial; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;&quot;&gt;&lt;code style=&quot;color: black; word-wrap: normal;&quot;&gt; java -jar opengrok.jar -W G:\opengrok-0.11.1\configuration.xml -c G:\ctags58\ctags.exe -P -S -v -s G:\CodeSource -d G:\opengrok-0.11.1\grokdata  
&lt;/code&gt;&lt;/pre&gt;
&lt;li&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;Launch Tomcat after the indexing in done. Open http://localhost:8080/source and wola you have a wicked fast source&amp;nbsp;browser.&amp;nbsp;&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;Reindex if you need to add new projects/pick new source etc.&lt;/span&gt;&lt;/li&gt;
&lt;/ol&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://algopadawan.blogspot.com/feeds/4628534085874344203/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://algopadawan.blogspot.com/2012/07/installing-opengrok-on-windows.html#comment-form' title='26 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/977483438624583257/posts/default/4628534085874344203'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/977483438624583257/posts/default/4628534085874344203'/><link rel='alternate' type='text/html' href='http://algopadawan.blogspot.com/2012/07/installing-opengrok-on-windows.html' title='Installing OpenGrok on Windows'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/10176620256158287366</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>26</thr:total></entry><entry><id>tag:blogger.com,1999:blog-977483438624583257.post-6766269746832635712</id><published>2012-05-08T21:55:00.000-07:00</published><updated>2012-05-08T22:10:59.680-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="c++"/><category scheme="http://www.blogger.com/atom/ns#" term="Linked List"/><category scheme="http://www.blogger.com/atom/ns#" term="Linked list reverse"/><title type='text'>K Reverse a linked list</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;br /&gt;
&lt;h2&gt;


&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;Q. K-Reverse a linked list.&lt;/span&gt;&lt;/h2&gt;
&lt;div&gt;
&lt;br /&gt;
&lt;ul style=&quot;text-align: left;&quot;&gt;
&lt;li&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;Examples.&amp;nbsp;&lt;/span&gt;&lt;/li&gt;
&lt;ul&gt;
&lt;li&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;Input. (K = 2) &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;A--&amp;gt;B--&amp;gt;C--&amp;gt;D--&amp;gt;E--&amp;gt;NULL&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;Output&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;(K = 2) &amp;nbsp;&lt;/span&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;B--&amp;gt;A--&amp;gt;D--&amp;gt;C--&amp;gt;E--&amp;gt;NULL&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;Input. (K = 3) &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;A--&amp;gt;B--&amp;gt;C--&amp;gt;D--&amp;gt;E--&amp;gt;NULL&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;Output&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;(K = 3) &amp;nbsp;&lt;/span&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;C--&amp;gt;B--&amp;gt;A--&amp;gt;E--&amp;gt;D--&amp;gt;NULL&lt;/span&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/ul&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;This problem is discussed in &lt;a href=&quot;http://algopadawan.blogspot.com/2012/05/reverse-alternate-nodes-in-linked-list.html&quot;&gt;here&lt;/a&gt;&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://algopadawan.blogspot.com/feeds/6766269746832635712/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://algopadawan.blogspot.com/2012/05/k-reverse-linked-list.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/977483438624583257/posts/default/6766269746832635712'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/977483438624583257/posts/default/6766269746832635712'/><link rel='alternate' type='text/html' href='http://algopadawan.blogspot.com/2012/05/k-reverse-linked-list.html' title='K Reverse a linked list'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/10176620256158287366</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-977483438624583257.post-1016774349068272084</id><published>2012-05-08T21:50:00.000-07:00</published><updated>2012-05-08T22:11:14.902-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="c++"/><category scheme="http://www.blogger.com/atom/ns#" term="Linked List"/><category scheme="http://www.blogger.com/atom/ns#" term="Linked list reverse"/><title type='text'>Reverse Alternate Nodes in a Linked List</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;h2&gt;
















&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;Q. Reverse Alternate Nodes in a Linked List.&lt;/span&gt;&lt;/h2&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;Good Resource for the basics on linked lists (&lt;a href=&quot;http://cslibrary.stanford.edu/103/&quot;&gt;Linked List 101&lt;/a&gt;).&amp;nbsp;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;Input.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;A--&amp;gt;B--&amp;gt;C--&amp;gt;D--&amp;gt;NULL&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;Output&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;B--&amp;gt;A--&amp;gt;D--&amp;gt;C--&amp;gt;NULL&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;Possible Solutions:&amp;nbsp;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;ul style=&quot;text-align: left;&quot;&gt;
&lt;li&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;Alternate Node Data Swap.&amp;nbsp;&lt;/span&gt;&lt;/li&gt;
&lt;ul&gt;
&lt;li&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;With two pointers(C1 and C2) we can point to the first node and second node and swap the Data in the two node and move the C1 to point to the third node and C2 to the fourth node and so on.&lt;/span&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/ul&gt;
&lt;ul&gt;
&lt;li&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;Alternate Node Swap. &amp;nbsp;&lt;/span&gt;&lt;ul&gt;
&lt;li&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;With three pointers C1, C2 and C3 pointed to A, B, C we can swap the first two nodes and then move the pointers to repeat the same.&lt;/span&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;ul style=&quot;text-align: left;&quot;&gt;
&lt;li&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;Generic solution&lt;/span&gt;&lt;/li&gt;
&lt;ul&gt;
&lt;li&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;Both are linear solutions but there is a fundamental flaw that we cannot expand this to swap three node or four nodes.&amp;nbsp;&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;A little more thought and it is the same as reversing &#39;N&#39; lists of length &#39;K&#39; were&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;E.g for a 3 way swap for input&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;A--&amp;gt;B--&amp;gt;C--&amp;gt;D--&amp;gt;E--&amp;gt;NULL we reverse list 1 C--&amp;gt;B--&amp;gt;A and then E--&amp;gt;D--&amp;gt;NULL and join them to be &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;/span&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;C--&amp;gt;B--&amp;gt;A--&amp;gt;E--&amp;gt;D--&amp;gt;NULL.&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;We already have the solution for &lt;a href=&quot;http://algopadawan.blogspot.com/2012/05/linked-list-reverse.html&quot;&gt;reversing&lt;/a&gt; the linked list&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;We can extend the same for K-Reverse as following&lt;/span&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/ul&gt;
&lt;/div&gt;
C++ code 

&lt;br /&gt;
&lt;pre class=&quot;prettyprint&quot;&gt;// Look at the Reversing linked list blog for class definitions, we are extending the same class here  
#include &quot;linkedList.h&quot;
void LinkedList::kReverseList(unsigned int k)
{
&amp;nbsp;
 Node* current = head;
 Node* tempHead = head;
 unsigned int counter = 1;
 while(NULL != current)
 {
  while(NULL != current &amp;amp;&amp;amp; counter &amp;gt;= k)
  {
   current = current-&amp;gt;next;
   counter++;
  }
 Node* tempNext = current-&amp;gt;Next;
 Node* tail = head;     // Current Head will be tail node
 current-&amp;gt;next = NULL;  // Break the linked list so that we can reverse it.
 nonRecursiveReverse(tempHead);
 tail-&amp;gt;Next = tempNext; // Fix the list again.
 tempHead = tempNext;   // New Head node for the next list
 current = tempNext;
 counter = 1;           //Reset Counter
 }
}
&lt;/pre&gt;
&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://algopadawan.blogspot.com/feeds/1016774349068272084/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://algopadawan.blogspot.com/2012/05/reverse-alternate-nodes-in-linked-list.html#comment-form' title='3 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/977483438624583257/posts/default/1016774349068272084'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/977483438624583257/posts/default/1016774349068272084'/><link rel='alternate' type='text/html' href='http://algopadawan.blogspot.com/2012/05/reverse-alternate-nodes-in-linked-list.html' title='Reverse Alternate Nodes in a Linked List'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/10176620256158287366</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>3</thr:total></entry><entry><id>tag:blogger.com,1999:blog-977483438624583257.post-3878671633705213166</id><published>2012-05-07T23:18:00.001-07:00</published><updated>2012-05-08T22:11:28.463-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="c++"/><category scheme="http://www.blogger.com/atom/ns#" term="Linked List"/><category scheme="http://www.blogger.com/atom/ns#" term="Linked list reverse"/><title type='text'>Linked List Reverse</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;h2&gt;














&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;Q. How to reverse a linked list.&lt;/span&gt;&lt;/h2&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;Good Resource for the basics on linked lists (&lt;a href=&quot;http://cslibrary.stanford.edu/103/&quot;&gt;Linked List 101&lt;/a&gt;).&amp;nbsp;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;Possible Solutions:&amp;nbsp;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;ul&gt;
&lt;li&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;Linear Solution&lt;/span&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Consider the following linked list ( A--&amp;gt;B--&amp;gt;C--&amp;gt;D--&amp;gt;NULL) the expected output is (D--&amp;gt;C--&amp;gt;B--&amp;gt;A--&amp;gt;NULL).&lt;/span&gt;&lt;br /&gt;
&lt;ul&gt;
&lt;li style=&quot;list-style-type: none;&quot;&gt;
&lt;ul&gt;
&lt;li&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;With one pointer to the Node &#39;A&#39; say current we can access the node &#39;A&#39; and node &#39;B&#39;. (current--&amp;gt;next). If we point the next node for B to A we get the following (A--&amp;gt;B--&amp;gt;A) however we lose the next node &#39;C&#39; and also have a loop A--&amp;gt;B--&amp;gt;A information.&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;We can fix this by trying with 2 extra nodes. Node &#39;prev&#39; points to A and node current points to B. So we can break the node link A--&amp;gt;B and point B--&amp;gt;A ( current points to prev) however we still lose the node C information.&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;Lets us try this approach now with 3 nodes. prev = NULL , current = A, next = B. We continue traversing to the end of the list while updating the &#39;current&#39; node to point to &#39;prev&#39; and moving the (prev, current and next nodes by one)&lt;/span&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;ul&gt;
&lt;li&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;Recursive Solution&amp;nbsp;
&lt;/span&gt;&lt;ul&gt;
&lt;li&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;This solution is more intutive. We are essentially trying to traverse till the end of the list and point each node next to its previous node i.e. traverse the list from the TAIL node (D here) D to C to B to A.&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;We use the same logic as above however we now recurseively traverse the linked list till the end of loop and point the current node to the prev node.&amp;nbsp;&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;In the above example we recurse till current = &#39;D&#39; and prev is &#39;C&#39; then point the current D next to C i.e. D--&amp;gt;C.&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;When we come of out the recursive call end noe current is C and prev is B so C--&amp;gt;B, so on till the head node&lt;/span&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;ul&gt;
&lt;li&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;Analysis of Solutions&amp;nbsp;&lt;/span&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;table align=&quot;left&quot; border=&quot;1&quot; style=&quot;border-color: #000000; border-style: solid; border-width: 1px;&quot;&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;No.&lt;/span&gt;&lt;/td&gt;
&lt;td&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;Solution&lt;/span&gt;&lt;/td&gt;
&lt;td&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;Space Complexity&lt;/span&gt;&lt;/td&gt;
&lt;td&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;Time Complexity&lt;/span&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;1.&lt;/span&gt;&lt;/td&gt;
&lt;td&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;Linear&lt;/span&gt;&lt;/td&gt;
&lt;td&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;O(1)&amp;nbsp;&lt;/span&gt;&lt;/td&gt;
&lt;td&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;O(N)&lt;/span&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;2.&lt;/span&gt;&lt;/td&gt;
&lt;td&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;Recursive&lt;/span&gt;&lt;/td&gt;
&lt;td&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;O(N) to allocate stack space&lt;/span&gt;&lt;/td&gt;
&lt;td&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;O(N)&lt;/span&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;&lt;/div&gt;
C++ code 

&lt;br /&gt;
&lt;pre class=&quot;prettyprint&quot;&gt;/*
 * LinkedList.h
 *
 *  Created on: Jul 6, 2011
 *  Author: vivekrajumuppalla
 */
#pragma once

#define NULL 0

class Node{
private :
 int m_data;
 Node* m_next;
public:
 Node(int data);
 ~Node();
 int getNodeData();
 Node* getNodeNext();
 void setNextNode(Node* nextNode);
};

Node::Node(int data)
{
 m_data = data;
 m_next = NULL;
}

Node::~Node()
{
 if(NULL != m_next)
 {
  delete m_next;
 }
}

int Node::getNodeData()
{
 return m_data;
}

Node* Node::getNodeNext()
{
 return m_next;
}

void setNextNode(Node* nextNode)
{
 m_next = nextNode;
}
&lt;/pre&gt;
&lt;pre class=&quot;prettyprint&quot;&gt;include &quot;listNode.h&quot;
#pragma once

class LinkedList
{
public:
 LinkedList();
 ~LinkedList();
 void recursiveReverse(Node*&amp;amp; headNode);
 void nonRecursiveReverse();

private:
 Node* head;
}
&lt;/pre&gt;
&lt;pre class=&quot;prettyprint&quot;&gt;#include &quot;linkedList.h&quot;
void LinkedList::nonRecursiveReverse()
{
        Node* prev = NULL;
 Node* current = head;
 Node* next = NULL;

 while(NULL != current)
 {
  next = current-&amp;gt;getNodeNext();
  current-&amp;gt;setNextNode(prev);
  prev = current;
  current = next;
 }
 head = prev;
}

// reference needed since we have to update the node not just its pointer 
void LinkedList::recursiveReverse(Node*&amp;amp; headNode) 
{
 if(NULL == headNode || NULL == headNode-&amp;gt;getNodeNext())
 {
  tail = headNode;
  return;
 }
 Node* nextNode = headNode-&amp;gt;getNodeNext();
 recursiveReverse(nextNode);
 nextNode-&amp;gt;setNextNode(headNode);
 headNode-&amp;gt;setNextNode(NULL); // This will cause last node to point to NULL
}
&lt;/pre&gt;
&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://algopadawan.blogspot.com/feeds/3878671633705213166/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://algopadawan.blogspot.com/2012/05/linked-list-reverse.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/977483438624583257/posts/default/3878671633705213166'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/977483438624583257/posts/default/3878671633705213166'/><link rel='alternate' type='text/html' href='http://algopadawan.blogspot.com/2012/05/linked-list-reverse.html' title='Linked List Reverse'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/10176620256158287366</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry></feed>