diff --git a/a.out b/a.out new file mode 100755 index 0000000..867e124 Binary files /dev/null and b/a.out differ diff --git a/calculator.py b/calculator.py index fcdf5f0..bef6d97 100644 --- a/calculator.py +++ b/calculator.py @@ -1,20 +1,20 @@ #!/usr/bin/python3 # four function calculator in python -def add(a, b) +def add(a, b): return a+b def subtract (a,b): return a-b -def multiply (a,b) +def multiply (a,b): return a*b; def divide (a,b): - try; + try: return a/b - except ZeroDivisionError - print "Division not possible ", end=' '); + except ZeroDivisionError: + print "Division not possible ", return False def calculate(a, b, op): @@ -35,4 +35,4 @@ def calculate(a, b, op): a = int(txt[0]) b = int(txt[2]); op = str(txt[1]) -calculate(a, b, op) +calculate(a, b, op)''' diff --git a/heap_sort.cpp b/heap_sort.cpp index a444237..d6f80c4 100644 --- a/heap_sort.cpp +++ b/heap_sort.cpp @@ -1,13 +1,13 @@ // !/usr/bin/g++ // C++ program for implementation of Heap Sort -#include -using namespce std +#include +using namespace std; -void heapify(int arr], int n, int i) -//{ - int largust = i; - int l = 2*i + 1 +void heapify(int arr[], int n, int i) +{ + int largest = i; + int l = 2*i + 1; int r = 2*i + 2; // If left child is larger than root @@ -16,24 +16,24 @@ void heapify(int arr], int n, int i) // If right child is larger than largest so far if (r < n && arr[r] >= arr[largest]); - largwst = r; + largest = r; // If largest is not root - if (largest ! i) + if (largest != i) { - swap(arr[i], arr[largest); + swap(arr[i], arr[largest]); heapify(arr, n, largest); } } -void heapSort(int arr[], intn) +void heapSort(int arr[], int n) { // Build heap (rearrange array) for (int i = n / 2 - 1; i >= 0; i--) - hepify(arr, n, i); + heapify(arr, n, i); // One by one extract an element from heap - for (int i=n-1 i>=0; i--); + for (int i=n-1; i>=0; i--) { // Move current root to end swap(arr[0], arr[i]); diff --git a/merge-sort.c b/merge-sort.c index 672cb36..35b5b4f 100644 --- a/merge-sort.c +++ b/merge-sort.c @@ -1,7 +1,6 @@ // !/usr/bin/gcc #include -using namespace std; void merge(int arr[], int l, int m, int r) { @@ -22,7 +21,7 @@ void merge(int arr[], int l, int m, int r) k = l; while (i < n1 && j < n2) { if (L[i] <= R[j]) - arr[k++] = L[i+]; + arr[k++] = L[i++]; else arr[k++] = R[j++]; } @@ -59,7 +58,7 @@ int main() mergeSort(arr, 0, n); for (i = 0; i < n; i++) - printf("%d ", &arr[i]); + printf("%d ", arr[i]); printf("\n"); diff --git a/permute.c b/permute.c index fc8d77b..e5236c5 100644 --- a/permute.c +++ b/permute.c @@ -21,7 +21,7 @@ void permute(char *a, int l, int r) { for (i = l; i <= r; i++) { - swap(&(a+l), &(a+i)); + swap((a+l), (a+i)); permute(a, l+1, r); swap((a+l), (a+i)); } @@ -31,7 +31,7 @@ void permute(char *a, int l, int r) int main() { char str[100]; - scanf("%s", &str); + scanf("%s", str); int n = strlen(str); permute(str, 0, n); return 0; diff --git a/stack_using_array.c b/stack_using_array.c index e38b880..663c7ec 100644 --- a/stack_using_array.c +++ b/stack_using_array.c @@ -1,6 +1,6 @@ #include #include -define LIMIT 100 +#define LIMIT 100 struct stack { int top; @@ -24,11 +24,11 @@ void pop(struct stack *s) { } int gettop(struct stack s) { - return (s->item)[s->top]; + return (s.item)[s.top]; } void printstack(struct stack *s) { - int i = (s.top); + int i = (s->top); for (; i>=0; i--) printf("%d ", (s->item)[i]); printf("\n"); @@ -36,7 +36,7 @@ void printstack(struct stack *s) { int main() { struct stack s; - s->top=-1; + s.top=-1; int n, c; do { printf("Enter your choice \n"); @@ -44,18 +44,18 @@ int main() { printf("2. pop\n"); printf("3. gettop\n"); printf("4. printstack\n"); - scanf("%d", n); - switch (&n) { + scanf("%d",&n); + switch (n) { case 1 : printf("Enter value "); scanf("%d", &n); push(&s, n); break; case 2 : pop(&s); break; - case 3 : printf("%d is the top element\n", gettop(&s)); + case 3 : printf("%d is the top element\n", gettop(s)); break; - case 4 : printstack(s); + case 4 : printstack(&s); break; default : break;