From 270ae47c767e6d1c9c7a92c295280c5ec4080ea8 Mon Sep 17 00:00:00 2001 From: nonihd-codes Date: Sun, 10 Apr 2016 23:00:57 +0530 Subject: [PATCH 1/3] Added visualization to Insertion Sort --- InsertionSort.py | 49 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 InsertionSort.py diff --git a/InsertionSort.py b/InsertionSort.py new file mode 100644 index 0000000..9bdc612 --- /dev/null +++ b/InsertionSort.py @@ -0,0 +1,49 @@ +import numpy +import matplotlib.pyplot + +''' +This code illustrates a bargraph representation of the the insertion sort in +each iteration. +>>>We have used 3 different colored bars in the graph. +>>>The green and red bars reperesent the 2 numbers currently being compared. +>>>The blue bars represent the numbers which are represent the other numbers. +''' + + +def insertionsort(alist): + for index in range(1, len(alist)): + currentvalue = alist[index] + position = index + bar(alist, index - 1, index, index) + while position > 0 and alist[position-1] > currentvalue: + bar(alist, position-1, position, index) + alist[position] = alist[position-1] + bar(alist, position-1, position, index) + position = position-1 + alist[position] = currentvalue + if position != index: + bar(alist, position, position+1, index) + return alist + + +def bar(alist, r, g, label): + N = len(alist) + ind = numpy.arange(N) + width = 0.25 + barlist = matplotlib.pyplot.bar(ind, alist, width, color='b') + barlist[r].set_color('r') + barlist[g].set_color('g') + matplotlib.pyplot.xlabel("Iteration number: %d" % (label)) + matplotlib.pyplot.pause(2) + matplotlib.pyplot.show() + matplotlib.pyplot.gcf().clear() + +if __name__ == '__main__': + alist = [ + 3, 1, 2, 5, 4 + ] + print alist + matplotlib.pyplot.ion() + insertionsort(alist) + + \ No newline at end of file From 1f128eee1f2b38328e39bc2604d2277416003bea Mon Sep 17 00:00:00 2001 From: nonihd-codes Date: Sun, 10 Apr 2016 23:01:47 +0530 Subject: [PATCH 2/3] Rename InsertionSort.py to adaLovelace/InsertionSort.py --- InsertionSort.py => adaLovelace/InsertionSort.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename InsertionSort.py => adaLovelace/InsertionSort.py (96%) diff --git a/InsertionSort.py b/adaLovelace/InsertionSort.py similarity index 96% rename from InsertionSort.py rename to adaLovelace/InsertionSort.py index 9bdc612..002125c 100644 --- a/InsertionSort.py +++ b/adaLovelace/InsertionSort.py @@ -46,4 +46,4 @@ def bar(alist, r, g, label): matplotlib.pyplot.ion() insertionsort(alist) - \ No newline at end of file + From 8858f834812b5d6b1bc67e78d36990e3bbb9d388 Mon Sep 17 00:00:00 2001 From: nonihd-codes Date: Fri, 15 Apr 2016 03:37:05 +0530 Subject: [PATCH 3/3] Creates README.md for adaLovelace --- adaLovelace/README.md | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 adaLovelace/README.md diff --git a/adaLovelace/README.md b/adaLovelace/README.md new file mode 100644 index 0000000..7779f97 --- /dev/null +++ b/adaLovelace/README.md @@ -0,0 +1,11 @@ +# Team Ada Lovelace +**Saloni Dalal** +* dalalsaloni96@gmail.com +* [@nonihd-codes](https://github.com/nonihd-codes) + +**Birva Patel** +* birva1@gmail.com +* [@tangled2096](https://github.com/tangled2096) + +# Contributions +1. Insertion Sort