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

Issue #163 #164

Open
wants to merge 3 commits into
base: main
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
9 changes: 4 additions & 5 deletions ExpressionTree.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include<stdio.h>
#include<stdlib.h>

// EXPRESSION TREE
struct node
{
char data;
Expand Down Expand Up @@ -49,7 +50,6 @@ void preorder(struct node *root)
preorder(root->left);
preorder(root->right);
}

}

void inorder(struct node *root)
Expand All @@ -60,7 +60,6 @@ void inorder(struct node *root)
printf("%c ",root->data);
inorder(root->right);
}

}

void postorder(struct node *root)
Expand All @@ -82,7 +81,7 @@ struct node *create_expression_tree(char *exp) // pass the postfix expression

struct node *temp;

while(exp[i] != '\0')
while(exp[i] != '\0') // use example ABC*+ and trace
{
ch = exp[i];
temp = (struct node *)malloc(sizeof(struct node));
Expand Down Expand Up @@ -112,13 +111,13 @@ int eval(struct node *root) // recursive function
case '-': return(eval(root->left) - eval(root->right));
case '*': return(eval(root->left) * eval(root->right));
case '/': return(eval(root->left) / eval(root->right));
default: printf("%c = ",root->data);
default: printf("%c = \n",root->data);
scanf("%d",&x);
return x;
}
}

void push(struct node **s, int *t, struct node *temp)
void push(struct node **s, int *t, struct node *temp) // s-stack, t-top, ** as it is stack of nodes
{
++(*t);
s[*t] = temp;
Expand Down
31 changes: 31 additions & 0 deletions QuickSort.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
def QuickSort(arr):

elements = len(arr)

#Base case
if elements < 2:
return arr

current_position = 0 #Position of the partitioning element

for i in range(1, elements): #Partitioning loop
if arr[i] <= arr[0]:
current_position += 1
temp = arr[i]
arr[i] = arr[current_position]
arr[current_position] = temp

temp = arr[0]
arr[0] = arr[current_position]
arr[current_position] = temp #Brings pivot to it's appropriate position

left = QuickSort(arr[0:current_position]) #Sorts the elements to the left of pivot
right = QuickSort(arr[current_position+1:elements]) #sorts the elements to the right of pivot

arr = left + [arr[current_position]] + right #Merging everything together

return arr

array_to_be_sorted = [4,2,7,3,1,6]
print("Original Array: ",array_to_be_sorted)
print("Sorted Array: ",QuickSort(array_to_be_sorted))
33 changes: 33 additions & 0 deletions Sets.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# add
fruits = {'apple','banana','cherry'}
fruits.add('orange')
print(fruits)

# pop - Remove a random item from the set
fruits = {"apple", "banana", "cherry"}
fruits.pop()
print(fruits)

# Union - Return a set that contains all items from both sets, duplicates are excluded
x = {"apple", "banana", "cherry"}
y = {"google", "microsoft", "apple"}
z = x.union(y)
print(z)

# Intersection - Return a set that contains the items that exist in both set x, and set y
x = {"apple", "banana", "cherry"}
y = {"google", "microsoft", "apple"}
z = x.intersection(y)
print(z)

# Difference - Return a set that contains the items that only exist in set x, and not in set y
x = {"apple", "banana", "cherry"}
y = {"google", "microsoft", "apple"}
z = x.difference(y)
print(z)

# Symmertic Difference - Return a set that contains all items from both sets, except items that are present in both sets
x = {"apple", "banana", "cherry"}
y = {"google", "microsoft", "apple"}
z = x.symmetric_difference(y)
print(z)