diff --git a/Arrays-Sorting/src/oddEvenSort.py b/Arrays-Sorting/src/oddEvenSort.py new file mode 100644 index 00000000..843e8927 --- /dev/null +++ b/Arrays-Sorting/src/oddEvenSort.py @@ -0,0 +1,28 @@ + +#Python Program to implement Odd-Even / Brick Sort +#A python program to implement odd-even sorting or Brick Sort. +#It is a kind of bubble sort since it is divided into two phases, +#i.e. odd phase & even phase and bubble sort is implemented on each of the phases. +def oddEvenSort(arr, n): + isSorted = 0 + while isSorted == 0: + isSorted = 1 + temp = 0 + for i in range(1, n-1, 2): + if arr[i] > arr[i+1]: + arr[i], arr[i+1] = arr[i+1], arr[i] + isSorted = 0 + + for i in range(0, n-1, 2): + if arr[i] > arr[i+1]: + arr[i], arr[i+1] = arr[i+1], arr[i] + isSorted = 0 + + return + +arr = [34, 2, 10, -9] +n = len(arr) +oddEvenSort(arr, n); + +for i in range(0, n): + print(arr[i], end = ' ') diff --git a/Arrays-searching/src/linear_search_recursion.py b/Arrays-searching/src/linear_search_recursion.py new file mode 100644 index 00000000..08ea42d4 --- /dev/null +++ b/Arrays-searching/src/linear_search_recursion.py @@ -0,0 +1,21 @@ +# Recursive function to search x in arr[l..r] +# Another python program to search an element linearly in an array using Recursion (Read again 💯 ) +#Why recursion? Because it makes the task easier and reduces time complexity. +def rec_search( arr, l, r, x): + if r < l: + return -1 + if arr[l] == x: + return l + if arr[r] == x: + return r + return rec_search(arr, l+1, r-1, x) + +# Main Code +arr = [12, 34, 54, 2, 3] +n = len(arr) +x = 3 +index = rec_search(arr, 0, n-1, x) +if index != -1: + print "Element", x,"is present at index %d" %(index) +else: + print "Element %d is not present" %(x) diff --git a/Data_Structure/src/Linked Lists/circular_linked_list.py b/Data_Structure/src/Linked Lists/circular_linked_list.py new file mode 100644 index 00000000..abbd7739 --- /dev/null +++ b/Data_Structure/src/Linked Lists/circular_linked_list.py @@ -0,0 +1,144 @@ +#Another python program to implement and Insert a node by taking an pointer pointing to locations one want to insert a node to. +#The insertion operations are carried out: +#a. in empty linked list +#b. at beginning of the linked list +#c. at end of the linked list +#d. in between the nodes + +class Node: + + def init(self, data): + + self.data = data + + self.next = None + +class CircularLinkedList: + + def init(self): + + self.last = None + + # for empty list + + def addToEmpty(self, data): + + if (self.last != None): + + return self.last + + # Creating the newnode temp + + temp = Node(data) + + self.last = temp + + # Create Link + + self.last.next = self.last + + return self.last + + def addBegin(self, data): + + if (self.last == None): + + return self.addToEmpty(data) + + temp = Node(data) + + temp.next = self.last.next + + self.last.next = temp + + return self.last + + def addEnd(self, data): + + if (self.last == None): + + return self.addToEmpty(data) + + temp = Node(data) + + temp.next = self.last.next + + self.last.next = temp + + self.last = temp + + return self.last + + def addAfter(self, data, item): + + if (self.last == None): + + return None + + temp = Node(data) + + p = self.last.next + + while p: + + if (p.data == item): + + temp.next = p.next + + p.next = temp + + if (p == self.last): + + self.last = temp + + return self.last + + else: + + return self.last + + p = p.next + + if (p == self.last.next): + + print(item, "not present in the list") + + break + + def traverse(self): + + if (self.last == None): + + print("List is empty") + + return + + temp = self.last.next + + while temp: + + print(temp.data, end = " ") + + temp = temp.next + + if temp == self.last.next: + + break + +if name == 'main': + + llist = CircularLinkedList() + + last = llist.addToEmpty(6) + + last = llist.addBegin(4) + + last = llist.addBegin(2) + + last = llist.addEnd(8) + + last = llist.addEnd(12) + + last = llist.addAfter(10,8) + + llist.traverse() diff --git a/README.md b/README.md index cc8ab107..bc80f8cc 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,5 @@ # **Scripts Dump!** +[![Open Source Love](https://firstcontributions.github.io/open-source-badges/badges/open-source-v1/open-source.svg)](https://github.com/firstcontributions/open-source-badges) [![Pull Requests Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg?style=flat)](http://makeapullrequest.com) > Your goto place to find and dump any script you want. > @@ -45,7 +46,6 @@ ScriptsDump is a complete repository of all kind of scripts we and you can think - **[Graph Algorithms](/Graph_Algorithms/src)** - ## Maintainers We're always looking out for people who're enthusiastic to work and collaborate with people. If you want to become a maintainer at ScriptsDump you can contact us support@codezoned.com