diff --git a/Bubble_sort.cpp b/Bubble_sort.cpp new file mode 100644 index 0000000..b26e059 --- /dev/null +++ b/Bubble_sort.cpp @@ -0,0 +1,32 @@ +//--------bubble sort---------// +using namespace std; +#include +void bubble_sort(int a[],int n) +{ + int temp; + for(int i=0;ia[j+1]) + { + temp = a[j]; + a[j]=a[j+1]; + a[j+1]=temp; + } + } + } + for(int i=0;i>n; + int arr[n]; + for(int i=0;i>arr[i]; + bubble_sort(arr,n); + +} diff --git a/DELETION_IN _BST.cpp.cpp b/DELETION_IN _BST.cpp.cpp deleted file mode 100644 index 5ab87d8..0000000 --- a/DELETION_IN _BST.cpp.cpp +++ /dev/null @@ -1,123 +0,0 @@ -using namespace std; -#include -struct node -{ - int data; - struct node*left=NULL; - struct node *right=NULL; -}*root=NULL; -struct node *insertnode(struct node *root,struct node *temp) -{ - if(root==NULL) - { - root=new node; - root->data=temp->data; - root->left=NULL; - root->right=NULL; - } - else if(root->data>temp->data) - { - if(root->left==NULL) - { - root->left=temp; - root->left->left=NULL; - root->left->right=NULL; - - } - else - { - insertnode(root->left,temp); - } - } - else if(root->datadata) - { - if(root->right==NULL) - { - root->right=temp; - root->right->left=NULL; - root->right->right=NULL; - } - else - { - insertnode(root->right,temp); - } - } - return root; -} -struct node * findmin(struct node* node) -{ - struct node* current = node; - while (current->left != NULL) - current = current->left; - - return current; -} -struct node *delete1(struct node *temp,int data) -{if(root==NULL) -return root; -else if(datadata) -{ - root->left=delete1(root->left,data); -} -else if(root->dataright=delete1(root->right,data); -} - else - { -if(root->left==NULL&&root->right==NULL) -{ -delete(root); -root=NULL; -} -else if(root->left==NULL) -{ - struct node *temp=root; - root=root->right; - delete(temp); -} - else if(root->right==NULL) -{ - struct node *temp=root; - root=root->left; - delete(temp); -} -else -{ -struct node*temp=findmin(root->right); -root->data=temp->data; -root->right=delete1(root->right,temp->data); -} -} -return root; -} -void traverse(struct node* node1) -{ - if (node1 == NULL) - return; - traverse(node1->left); - cout << node1->data << " "; -traverse(node1->right); - -} -int main() -{ - int n; - cin>>n; - int data1; - struct node *p=NULL; - for(int i=0;i>data1; - struct node *temp=new struct node(); - temp->data=data1; - temp->left=NULL; - temp->right=NULL; - p=insertnode(p,temp); - } - int p1; - cin>>p1; - traverse(root); - root=delete1(root,p1); - traverse(root); -} diff --git a/DELETION_IN _BST.cpp.exe b/DELETION_IN _BST.cpp.exe deleted file mode 100644 index 1a8e173..0000000 Binary files a/DELETION_IN _BST.cpp.exe and /dev/null differ diff --git a/IN_ORDER_BINARY TREE.cpp b/IN_ORDER_BINARY TREE.cpp deleted file mode 100644 index 93d6db7..0000000 --- a/IN_ORDER_BINARY TREE.cpp +++ /dev/null @@ -1,72 +0,0 @@ -#include -using namespace std; -struct node -{ - struct node *left; - int data; - struct node *right; -}*root=NULL; - -struct node *insertnode(struct node *root,struct node *temp) -{ - - if(root==NULL) - { - root=new node; - root->data=temp->data; - root->left=NULL; - root->right=NULL; - } - else if(root->datadata) - { - if(root->right==NULL) - { - root->right=temp; - root->right->left=NULL; - root->right->right=NULL; - } - else - { - insertnode(root->right,temp); - } - } - else if(root->data>temp->data) - { - if(root->left==NULL) - { - root->left=temp; - root->left->left=NULL; - root->left->right=NULL; - } - else - { - insertnode(root->left,temp); - } - } -return root; -} -void traverse(struct node* node1) -{ - if (node1 == NULL) - return; - traverse(node1->left); - cout << node1->data << " "; - traverse(node1->right); - - -} -int main() -{ - int data1; - struct node *temp,*p=NULL; - for(int i=0;i<5;i++) - { - cin>>data1; - struct node *temp=new struct node(); - temp->data=data1; - temp->left=NULL; - temp->right=NULL; - p=insertnode(p,temp); - } - traverse(p); -} diff --git a/IN_ORDER_BINARY TREE.exe b/IN_ORDER_BINARY TREE.exe deleted file mode 100644 index b8f7ad6..0000000 Binary files a/IN_ORDER_BINARY TREE.exe and /dev/null differ diff --git a/POST_ORBER_BINARY_TREE.cpp.cpp b/POST_ORBER_BINARY_TREE.cpp.cpp deleted file mode 100644 index eb2ae33..0000000 --- a/POST_ORBER_BINARY_TREE.cpp.cpp +++ /dev/null @@ -1,73 +0,0 @@ -#include -using namespace std; -struct node -{ - struct node *left; - int data; - struct node *right; -}*root=NULL; - -struct node *insertnode(struct node *root,struct node *temp) -{ - - if(root==NULL) - { - root=new node; - root->data=temp->data; - root->left=NULL; - root->right=NULL; - } - else if(root->datadata) - { - if(root->right==NULL) - { - root->right=temp; - root->right->left=NULL; - root->right->right=NULL; - } - else - { - insertnode(root->right,temp); - } - } - else if(root->data>temp->data) - { - if(root->left==NULL) - { - root->left=temp; - root->left->left=NULL; - root->left->right=NULL; - } - else - { - insertnode(root->left,temp); - } - } -return root; -} -void traverse(struct node* node1) -{ - if (node1 == NULL) - return; - traverse(node1->left); - traverse(node1->right); - cout << node1->data << " "; - -} -int main() -{ - int data1; - struct node *temp,*p=NULL; - for(int i=0;i<5;i++) - { - cin>>data1; - struct node *temp=new struct node(); - temp->data=data1; - temp->left=NULL; - temp->right=NULL; - p=insertnode(p,temp); - } - traverse(p); -} - - diff --git a/POST_ORBER_BINARY_TREE.cpp.exe b/POST_ORBER_BINARY_TREE.cpp.exe deleted file mode 100644 index 1164643..0000000 Binary files a/POST_ORBER_BINARY_TREE.cpp.exe and /dev/null differ diff --git a/PRE_ORDER_BINARY_TREE,cpp.cpp b/PRE_ORDER_BINARY_TREE,cpp.cpp deleted file mode 100644 index d7d0e8c..0000000 --- a/PRE_ORDER_BINARY_TREE,cpp.cpp +++ /dev/null @@ -1,72 +0,0 @@ -#include -using namespace std; -struct node -{ - struct node *left; - int data; - struct node *right; -}*root=NULL; - -struct node *insertnode(struct node *root,struct node *temp) -{ - - if(root==NULL) - { - root=new node; - root->data=temp->data; - root->left=NULL; - root->right=NULL; - } - else if(root->datadata) - { - if(root->right==NULL) - { - root->right=temp; - root->right->left=NULL; - root->right->right=NULL; - } - else - { - insertnode(root->right,temp); - } - } - else if(root->data>temp->data) - { - if(root->left==NULL) - { - root->left=temp; - root->left->left=NULL; - root->left->right=NULL; - } - else - { - insertnode(root->left,temp); - } - } -return root; -} -void traverse(struct node* node1) -{ - if (node1 == NULL) - return; - cout << node1->data << " "; - traverse(node1->left); - traverse(node1->right); - - -} -int main() -{ - int data1; - struct node *temp,*p=NULL; - for(int i=0;i<5;i++) - { - cin>>data1; - struct node *temp=new struct node(); - temp->data=data1; - temp->left=NULL; - temp->right=NULL; - p=insertnode(p,temp); - } - traverse(p); -} diff --git a/PRE_ORDER_BINARY_TREE,cpp.exe b/PRE_ORDER_BINARY_TREE,cpp.exe deleted file mode 100644 index 88db8c3..0000000 Binary files a/PRE_ORDER_BINARY_TREE,cpp.exe and /dev/null differ diff --git a/SEARCH_&_DELETION_IN_BST.cpp.cpp b/SEARCH_&_DELETION_IN_BST.cpp.cpp deleted file mode 100644 index ed0adeb..0000000 --- a/SEARCH_&_DELETION_IN_BST.cpp.cpp +++ /dev/null @@ -1,94 +0,0 @@ -using namespace std; -#include -struct node -{ - int data; - struct node *left; - struct node *right; -}*root=NULL; -struct node *insertnode(struct node *root,struct node *t) -{ - if(root==NULL) - { - root=new node; - root=t; - } - else if(root->data>t->data) - { - if(root->left==NULL) - { - root->left=t; - t->left=NULL; - t->right=NULL; - } - else - { - insertnode(root->left,t); - } - } - else if(root->datadata) - { - if(root->right==NULL) - { - root->right=t; - t->left=NULL; - t->right=NULL; - } - else - { - insertnode(root->right,t); - } - } -return root; -} -struct node *k=NULL; -void search(struct node *node1,int k) -{ - if (node1->data == k) - cout<<"element found"; - else if(kdata&&node1->left!=NULL) - search(node1->left,k); - else if(k>node1->data&&node1->right!=NULL) -search(node1->right,k); - else - cout<<"elemnt not found"; -} - -void deletion(struct node* node1) -{ - if(node1->left==NULL&&node1->right==NULL) - { - k->left=NULL; - } - else - { - k=node1; - deletion(node1->left); - } -} - void traverse(struct node* node1) - { - struct node*p=node1; - if (p == NULL) - return; - traverse(p->left); - cout << p->data << " "; - traverse(p->right); - } - int main() -{ - struct node *p=NULL; - for(int i =0;i<6;i++) - { - struct node *temp=new struct node(); - cin>>temp->data; - temp->left=NULL; - temp->right=NULL; - p=insertnode(p,temp); - } - int k; - cin>>k; - search(p,k); - deletion(p); - traverse(p); -} diff --git a/SEARCH_&_DELETION_IN_BST.cpp.exe b/SEARCH_&_DELETION_IN_BST.cpp.exe deleted file mode 100644 index 1c3e4c4..0000000 Binary files a/SEARCH_&_DELETION_IN_BST.cpp.exe and /dev/null differ diff --git a/cicularqueue.cpp b/cicularqueue.cpp deleted file mode 100644 index bbda887..0000000 --- a/cicularqueue.cpp +++ /dev/null @@ -1,68 +0,0 @@ -using namespace std; -#include -int arr[20]; -int front =-1; -int rear=-1; -int size =5; -void insertion(int s) -{ - if(rear==-1&&front==-1) - { - rear=rear+1; - front = front+1; - arr[rear]=s; - } -else if(front==0&&rear==size-1) - { - cout<<"overflow"< -struct node -{ - int data; - struct node* next=NULL; -}; -struct node *front=NULL; -struct node *rear=NULL; -struct node *createnode() -{ - struct node *p; - p=new(struct node); - cin>>p->data; - p->next=NULL; -} -struct node *insertnode() -{ - - struct node *p; - p=createnode(); - if(front==NULL&&rear==NULL) - { - front=p; - rear=p; - p->next=NULL; - } - else - { - struct node *t; - t=front; - while(t->next!=NULL) - { - t=t->next; - } - t->next=p; - p->next=NULL; - rear=p; -} -} -struct node *deletion() -{ - if(rear->next==NULL&&front->next==NULL) - { - front=NULL; - cout<<"nothing to be deleted"<next==front->next) - { - rear=NULL; - front=NULL; - } - else if(front->next==NULL&&front!=rear) - { - front=NULL; - } - else - { - front = front->next; - } - return front; -} -int main() -{ - insertnode(); - insertnode(); - insertnode(); - insertnode(); - deletion(); - deletion(); - deletion(); - deletion(); - // deletion(); - while(front->next!=NULL) - { - cout<data; - front=front->next; - - } - cout<data; - { - - } -} diff --git a/circularlinkedqueue.exe b/circularlinkedqueue.exe deleted file mode 100644 index 68aa060..0000000 Binary files a/circularlinkedqueue.exe and /dev/null differ diff --git a/circularlinkedqueuee.cpp b/circularlinkedqueuee.cpp deleted file mode 100644 index 77217fb..0000000 --- a/circularlinkedqueuee.cpp +++ /dev/null @@ -1,84 +0,0 @@ -using namespace std; -#include -struct node -{ - int data; - struct node* next=NULL; -}; -struct node *front=NULL; -struct node *rear=NULL; -struct node *createnode() -{ - struct node *p; - p=new(struct node); - cin>>p->data; - p->next=NULL; -} -struct node *insertnode() -{ - - struct node *p; - p=createnode(); - if(front==NULL&&rear==NULL) - { - front=p; - rear=p; - p->next=NULL; - } - else - { - struct node *t; - t=front; - while(t->next!=NULL) - { - t=t->next; - } - t->next=p; - p->next=NULL; - rear=p; -} -} -struct node *deletion() -{ - if(rear->next==NULL&&front->next==NULL) - { - front=NULL; - rear=NULL; - cout<<"nothing to be deleted"<next==front->next) - { - rear=NULL; - front=NULL; - } - else if(front->next==NULL&&front!=rear) - { - front=NULL; - } - else - { - front = front->next; - } - return front; -} -int main() -{ - insertnode(); - insertnode(); - insertnode(); - insertnode(); - deletion(); - deletion(); - deletion(); - deletion(); - deletion(); - while(front!=NULL) - { - cout<data; - front=front->next; - - } - { - - } -} diff --git a/circularqueue.cpp b/circularqueue.cpp deleted file mode 100644 index 118947c..0000000 --- a/circularqueue.cpp +++ /dev/null @@ -1,83 +0,0 @@ -using namespace std; -#include -struct node -{ - int data; - struct node* next=NULL; -}; -struct node *front=NULL; -struct node *rear=NULL; -struct node *createnode() -{ - struct node *p; - p=new(struct node); - cin>>p->data; - p->next=NULL; -} -struct node *insertnode() -{ - - struct node *p; - p=createnode(); - if(front==NULL&&rear==NULL) - { - front=p; - rear=p; - p->next=NULL; - } - else - { - struct node *t; - t=front; - while(t->next!=NULL) - { - t=t->next; - } - t->next=p; - p->next=NULL; - rear=p; -} -} -/*struct node *deletion() -{ - if(rear->next==NULL&&front->next==NULL) - { - cout<<"nothing to be deleted"<next==front->next) - { - rear=NULL; - front=NULL; - } - else if(front->next==NULL&&front!=rear) - { - front=NULL; - } - else - { - front = front->next; - } - return front; -}*/ -int main() -{ - insertnode(); - insertnode(); - insertnode(); - insertnode(); - //deletion(); - //deletion(); - //deletion(); - // deletion(); - // deletion(); - while(front->next!=NULL) - { - cout<data; - front=front->next; - - } - cout<data; - { - - } -} diff --git a/circularqueue.exe b/circularqueue.exe deleted file mode 100644 index 4050682..0000000 Binary files a/circularqueue.exe and /dev/null differ diff --git a/deque.cpp b/deque.cpp deleted file mode 100644 index 4d156d5..0000000 --- a/deque.cpp +++ /dev/null @@ -1,93 +0,0 @@ -using namespace std; -#include -int left1=-1; -int right1=-1; -int arr[90]={0}; -int size=7; -void right_insertion(int p) -{ - if((left1==-1 )&&(right1==-1)) - { - left1=left1+1; - right1=right1+1; - arr[right1]=p; - } - else if((right1==size-1)&&left1==0) - { - cout<<"overflow"< -int lft=-1; -int rght = -1; -int arr[34]={0}; -int mx=5; -insertion_left1(int p) -{ - if(rght==mx-1&&lft==0) - { - cout<<"overflow"< -void sort(int arr[],int n) -{ - int temp; - int k=1; - while(k<=n-1) - { - - temp=arr[k]; - int j=k-1; - while(temp<=arr[j]) - { - arr[j+1]=arr[j]; - arr[j]=temp; - j--; - } - k++; - - } - for(int i=0;i>n; - int arr[n]; - for(int i=0;i>arr[i]; - sort(arr,n); -} +// INSERTION SORT + +using namespace std; +#include +void sort(int arr[],int n) +{ + int temp; + int k=1; + while(k<=n-1) + { + + temp=arr[k]; + int j=k-1; + while(temp<=arr[j]) + { + arr[j+1]=arr[j]; + arr[j]=temp; + j--; + } + k++; + + } + for(int i=0;i>n; + int arr[n]; + for(int i=0;i>arr[i]; + sort(arr,n); +} diff --git a/merge_sort.cpp b/merge_sort.cpp index c4a16da..18102fd 100644 --- a/merge_sort.cpp +++ b/merge_sort.cpp @@ -1,83 +1,83 @@ -//MERGE SORT -using namespace std; -#include -void merge(int arr[], int l, int m, int r) ; -merge_sort(int arr[],int low,int high) -{ - - if(low>n; - int arr[n]; - int low=0; - int high=n; - for(int i=0;i>arr[i]; - } - - merge_sort(arr,low,high-1); - print(arr,n); -} +//MERGE SORT +using namespace std; +#include +void merge(int arr[], int l, int m, int r) ; +merge_sort(int arr[],int low,int high) +{ + + if(low>n; + int arr[n]; + int low=0; + int high=n; + for(int i=0;i>arr[i]; + } + + merge_sort(arr,low,high-1); + print(arr,n); +} diff --git a/priorityqueue.cpp b/priorityqueue.cpp deleted file mode 100644 index 654b8d1..0000000 --- a/priorityqueue.cpp +++ /dev/null @@ -1,71 +0,0 @@ -using namespace std; -#include -struct node -{ - int data; - int pri; - struct node *next=NULL; -}; -struct node* start=NULL; -struct node* createnode() -{ - struct node *temp; - temp = new(struct node); - cin>>temp->data; - cin>>temp->pri; - temp->next=NULL; -} -struct node *insertnode() -{ - struct node *t; - t = createnode(); - struct node *t1; - struct node *k; - - if(start==NULL||t->pripri) - { - t->next=start; - start=t; - } - else - { - t1=start; - while(t1->next!=NULL&&t1->pripri) - { - k=t1; - t1=t1->next; - } - if(t1->pri>t->pri) - { - k->next=t; - t->next=t1; - } - else - {42 - - t1->next=t; - t->next=NULL; - - - } - - } -} -void traverse() -{ - struct node *t; - t=start; - while(t!=NULL) - { - cout<data<<"--> "<pri<next; - } -} -int main() -{ - for(int i=0;i<5;i++) - { - insertnode(); - } - traverse(); -} diff --git a/priorityqueue.exe b/priorityqueue.exe deleted file mode 100644 index 3605e45..0000000 Binary files a/priorityqueue.exe and /dev/null differ diff --git a/queue.cpp b/queue.cpp deleted file mode 100644 index a8de25e..0000000 --- a/queue.cpp +++ /dev/null @@ -1,59 +0,0 @@ -using namespace std; -#include -#include -int rear=-1; -int front=-1; -int size=5; -int q[5]; -void insertion(int c) -{ - - if(rear==-1 && front==-1) - { - front+=1; - rear+=1; - q[rear]=c; - } - else if(rear==size-1) - { - cout<<"overflow"<rear) - { - cout<<"underflow"< -#include - stacks; - stacks2; - -void deletion() - { - int p=0; - if((!s.empty())||s2.empty()) - { - while(!s.empty()) - { - p=s.top(); - s.pop(); - s2.push(p); - - } - s2.pop(); - return s2; - } - else - { - /*while(!s2.empty()) - { - p=s2.top(); - s2.pop(); - s.push(p); - }*/ - s2.pop(); - return s2; - } - } -int main() -{ -//stackk; -s.push(3); -s.push(31); -s.push(23); -s.push(45); -s.push(37); -deletion(); -/*k=deletion(); -k=deletion(); -k=deletion();*/ -if(s.empty()) -{ - - k.push(100); - - } -else -{ - s2.push(100); -} -while(!k.empty()) -{ - cout< -void swap(int *p,int *n) -{ - int temp; - temp=*p; - *p=*n; - *n=temp; -} -int partion(int arr[],int low,int high) -{ - int pivot=arr[high]; - int i=low-1; - for(int j=low;j<=high-1;j++) - { - if(arr[j]>n; - int arr[n]; - for(int i=0;i>arr[i]; - int low= 0; - int high=n; - quick(arr,low,high-1); - print(arr,n); -} +// QUICK SORT +using namespace std; +#include +void swap(int *p,int *n) +{ + int temp; + temp=*p; + *p=*n; + *n=temp; +} +int partion(int arr[],int low,int high) +{ + int pivot=arr[high]; + int i=low-1; + for(int j=low;j<=high-1;j++) + { + if(arr[j]>n; + int arr[n]; + for(int i=0;i>arr[i]; + int low= 0; + int high=n; + quick(arr,low,high-1); + print(arr,n); +} diff --git a/selection_sort.cpp b/selection_sort.cpp index 708761a..29cc394 100644 --- a/selection_sort.cpp +++ b/selection_sort.cpp @@ -1,32 +1,32 @@ -//SELECTION SORT -using namespace std; -#include -selection_sort(int arr[],int n) -{ int temp=0; -int min; - for(int i=0;i>n; - int arr[n]; - for(int i=0;i>arr[i]; - selection_sort(arr,n); - -} +//SELECTION SORT +using namespace std; +#include +selection_sort(int arr[],int n) +{ int temp=0; +int min; + for(int i=0;i>n; + int arr[n]; + for(int i=0;i>arr[i]; + selection_sort(arr,n); + +}