diff --git a/ExpressionTree.c b/ExpressionTree.c index 328b160..1c29b3c 100644 --- a/ExpressionTree.c +++ b/ExpressionTree.c @@ -1,6 +1,7 @@ #include #include +// EXPRESSION TREE struct node { char data; @@ -49,7 +50,6 @@ void preorder(struct node *root) preorder(root->left); preorder(root->right); } - } void inorder(struct node *root) @@ -60,7 +60,6 @@ void inorder(struct node *root) printf("%c ",root->data); inorder(root->right); } - } void postorder(struct node *root) @@ -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)); @@ -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; diff --git a/QuickSort.py b/QuickSort.py new file mode 100644 index 0000000..d54ecdb --- /dev/null +++ b/QuickSort.py @@ -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)) diff --git a/Sets.py b/Sets.py new file mode 100644 index 0000000..ef053ea --- /dev/null +++ b/Sets.py @@ -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)