<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: theIndianDev</title>
    <description>The latest articles on DEV Community by theIndianDev (@theindiandev1).</description>
    <link>https://dev.to/theindiandev1</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F159497%2F6aca1e3d-72c5-4fe9-80a2-a24f65ac443c.png</url>
      <title>DEV Community: theIndianDev</title>
      <link>https://dev.to/theindiandev1</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/theindiandev1"/>
    <language>en</language>
    <item>
      <title>Reversing Array In Place</title>
      <dc:creator>theIndianDev</dc:creator>
      <pubDate>Sat, 01 Jun 2019 15:05:55 +0000</pubDate>
      <link>https://dev.to/theindiandev1/reversing-array-in-place-55gp</link>
      <guid>https://dev.to/theindiandev1/reversing-array-in-place-55gp</guid>
      <description>&lt;p&gt;Hey, hey, hey this is my first article. Gonna keep it really short. Began learning data structures and algorithms from today. I had this thought whether is there a way to reverse an array in place without using additional space (i.e. like a new array). You guessed it right, we do have a way. This is the idea:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--kPQpgEdP--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/kw3b8c3kc5xvk6t0vwm8.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--kPQpgEdP--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/kw3b8c3kc5xvk6t0vwm8.png" alt=""&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;We are going to iterate for (N/2) times (N = length of the array) and swap the first half of the array with the second half. We are only iterating n/2 times. How cool is that, let me know what you guys think.&lt;/p&gt;

&lt;p&gt;The Code:&lt;/p&gt;



&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;class Array:
  def __init__(self):
    self.array = []
    self.length = 0

  def reverse(self):
    for i in range(len(self.array)/2):
      current_position = i
      swap_position = len(self.array) - (i + 1)

      temp = self.array[swap_position]
      current_value = self.array[current_position]
      self.array[swap_position] = current_value
      self.array[current_position] = temp

    return self.array


array = Array()
array.append(1)
array.append(2)
array.append(3)
array.append(4)
array.append(5)
array.append(6)
array.append(7)
print array.reverse() 
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



</description>
      <category>algorithms</category>
      <category>datastructures</category>
      <category>computerscience</category>
    </item>
  </channel>
</rss>
