Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bug fixes #2

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added a.out
Binary file not shown.
12 changes: 6 additions & 6 deletions calculator.py
Original file line number Diff line number Diff line change
@@ -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):
Expand All @@ -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)'''
24 changes: 12 additions & 12 deletions heap_sort.cpp
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
// !/usr/bin/g++

// C++ program for implementation of Heap Sort
#include <iostream.h>
using namespce std
#include <iostream>
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
Expand All @@ -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]);
Expand Down
5 changes: 2 additions & 3 deletions merge-sort.c
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// !/usr/bin/gcc

#include <stdio.h>
using namespace std;

void merge(int arr[], int l, int m, int r)
{
Expand All @@ -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++];
}
Expand Down Expand Up @@ -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");

Expand Down
4 changes: 2 additions & 2 deletions permute.c
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
Expand All @@ -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;
Expand Down
16 changes: 8 additions & 8 deletions stack_using_array.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include <stdio.h>
#include <stdlib.h>
define LIMIT 100
#define LIMIT 100

struct stack {
int top;
Expand All @@ -24,38 +24,38 @@ 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");
}

int main() {
struct stack s;
s->top=-1;
s.top=-1;
int n, c;
do {
printf("Enter your choice \n");
printf("1. push\n");
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;
Expand Down