Skip to content

Commit

Permalink
Uploaded Files to Repo
Browse files Browse the repository at this point in the history
Uploaded some files which have been worked upon recently.
  • Loading branch information
Animesh-Ghosh authored Sep 19, 2018
1 parent 3904840 commit ea5c73e
Show file tree
Hide file tree
Showing 3 changed files with 129 additions and 0 deletions.
56 changes: 56 additions & 0 deletions Determinant.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
#include <stdio.h>
#include <conio.h>
#include <math.h>
#define MAXSIZE 5 //size of matrix can be changed from here

void Enter(int A[][MAXSIZE], int);
void Show(int A[][MAXSIZE], int);
int detA(int A[][MAXSIZE], int);
void Minor(int A[][MAXSIZE], int M[][MAXSIZE], int, int, int);

void main() {
int A[MAXSIZE][MAXSIZE], size, det;
scanf("%d", &size);
Enter(A, size);
det = detA(A, size);
printf("%d", det);
getch();
}

void Enter(int A[][MAXSIZE], int size) {
int i, j;
for (i=0; i<size; i++) {
for (j=0; j<size; j++) {
scanf("%d", &A[i][j]);
}
}
}

int detA(int A[][MAXSIZE], int size) {
int det = 0, i;
int M[size-1][size-1];
if (size==1) return A[0][0];
else {
for (i=0; i<size; i++) {
Minor(A, M, 0, i, size);
det = det + (pow(-1, i) * A[0][i] * detA(M, size-1));
}
return det;
}
}

void Minor(int A[][MAXSIZE], int M[][MAXSIZE], int I, int J, int size) {
int i, j, k=0, l=0;
for (i=0; i<size; i++) {
if (i!=I) {
for (j=0; j<size; j++) {
if (j!=J) {
M[k][l] = A[i][j];
l++;
}
}
l=0;
k++;
}
}
}
10 changes: 10 additions & 0 deletions TestShift.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# include <stdio.h>
# include <string.h>
# include <conio.h>

int main () {
((-1 >> 1) < 0) ? puts ("Arithmetic Shift") : puts ("Logical Shift");
printf ("%d", ((-1 >> 1)));
getch ();
return 0;
}
63 changes: 63 additions & 0 deletions Tree.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
# include <iostream>

//didn't use whole std namespace since the build would become bulkier
//using namespace std;
using std::cin;
using std::cout;
using std::endl;

// data structure
struct NODE {
int data;
NODE *left;
NODE *right;
};

// insert function
// got help from a person on the internet! thank you Discord!
NODE* Insert_Node (NODE *root, int& data) {
if (root == NULL) {
root = new NODE;
root->data = data;
root->left = root->right = NULL;
return root;
}
else if (data < root->data) {
root->left = Insert_Node (root->left, data);
}
else if (root->data < data) {
root->right = Insert_Node (root->right, data);
}
}

// traverse tree
void Traverse (NODE *root) {
// made this on the first try!!! BOI!!!
NODE *cur = root;
if (cur->left != NULL) Traverse (cur->left);
cout<<cur->data<<" ";
if (cur->right != NULL) Traverse (cur->right);
}

// main
int main () {
NODE *root = NULL;
//int datum[] = {2, 0, 1, 5, 3, 4}; //sample input: 2, 0, 1, 5, 3, 4
int N, data;
cout<<"Enter number of elements to be inserted: ";
cin>>N;
for (int i = 0; i < N ; i++) {
cout<<"Enter data element: ";
cin>>data;
root = Insert_Node (root, data);
}
/*
cout<<"Level 0:\t"<<root->data<<endl;
cout<<"Level 1:\t"<<root->left->data<<"\t"<<root->right->data<<endl;
cout<<"Level 2:\t"<<root->left->right->data<<"\t"<<root->right->left->data<<endl;
cout<<"Level 3:\t"<<root->right->left->right->data<<endl;
*/
cout<<"Tree in INORDER traversal: "<<endl;
Traverse (root);
return 0;
}

0 comments on commit ea5c73e

Please # to comment.