Repository: keon/algorithms (python)

Issue:
Issue in the code of algorithms/algorithms/stack/is_sorted.py
Some changes need to be made in the code. 
1)The first 2 return statements have to be changed to break statements. This ensures that the code after the first for loop is executed. Previously it would never execute the latter part. 
2)The second append statement should add elements to stack and not storage_stack. Try the test case [3,4,7,8,5,6]. The program returns True. It should return False.

```
def is_sorted(stack):
    storage_stack = []
    for i in range(len(stack)):
        if len(stack) == 0:
            break    # return
        first_val = stack.pop()
        if len(stack) == 0:
            break    # return
        second_val = stack.pop()
        if first_val < second_val:
            return False
        storage_stack.append(first_val)
        stack.append(second_val)    # storage_stack.append(second_val)

    # Backup stack
    for i in range(len(storage_stack)):
        stack.append(storage_stack.pop())

    return True
```

Pull request:
Update is_sorted.py
Changes made-
1) The first 2 return statements have been changed to break statements. This ensures that the code after the first for loop is executed. Previously it would never execute the latter part.
2) The second append statement should add elements to stack and not storage_stack. Try the test case [3,4,7,8,5,6]. The program returns True. It should return False.

(Put an `X` inside the `[ ]` to denote check mark `[X]`.)


- [ ] **If creating a new file :**
  - [ ] added links to it in the README files ?
  - [ ] included tests with it ?
  - [ ] added description (overview of algorithm, time and space compleixty, and possible edge case) in docstrings ?

- [x] **if done some changes :**
  - [X] wrote short description in the PR explaining what the changes do ?
  - [X] Fixes #401  if related to any issue

- [ ] **other**


Patch:
diff --git a/algorithms/search/search_rotate.py b/algorithms/search/search_rotate.py
index ade0270..a92a15e 100644
--- a/algorithms/search/search_rotate.py
+++ b/algorithms/search/search_rotate.py
@@ -37,9 +37,6 @@ There are 2 possible solution: iterative and recursion.
 Recursion helps you understand better the above algorithm explanation
 """
 def search_rotate(array, val):
-    if not array:
-        return -1
-
     low, high = 0, len(array) - 1
     while low <= high:
         mid = (low + high) // 2
diff --git a/algorithms/stack/is_sorted.py b/algorithms/stack/is_sorted.py
index 8824dfa..0a69d83 100644
--- a/algorithms/stack/is_sorted.py
+++ b/algorithms/stack/is_sorted.py
@@ -13,15 +13,15 @@ def is_sorted(stack):
     storage_stack = []
     for i in range(len(stack)):
         if len(stack) == 0:
-            return True
+            break
         first_val = stack.pop()
         if len(stack) == 0:
-            return True
+            break
         second_val = stack.pop()
         if first_val < second_val:
             return False
         storage_stack.append(first_val)
-        storage_stack.append(second_val)
+        stack.append(second_val)
 
     # Backup stack
     for i in range(len(storage_stack)):


Test patch:
diff --git a/tests/test_stack.py b/tests/test_stack.py
index d04b27f..78822bc 100644
--- a/tests/test_stack.py
+++ b/tests/test_stack.py
@@ -25,6 +25,7 @@ class TestSuite(unittest.TestCase):
         # Test case: bottom [6, 3, 5, 1, 2, 4] top
         self.assertFalse(is_sorted([6, 3, 5, 1, 2, 4]))
         self.assertTrue(is_sorted([1, 2, 3, 4, 5, 6]))
+        self.assertFalse(is_sorted([3, 4, 7, 8, 5, 6]))
 
     def test_remove_min(self):
         # Test case: bottom [2, 8, 3, -6, 7, 3] top