Skip to content

Commit

Permalink
Merge branch 'master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
SubCoder1 committed Oct 26, 2018
2 parents 3f396c9 + 99160ab commit 375df2d
Show file tree
Hide file tree
Showing 42 changed files with 1,821 additions and 88 deletions.
2 changes: 2 additions & 0 deletions Contributor.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ This is a repo created to remember the Hacktober Fest organized by Github, Digit
* [Saurav Jaiswal](https://github.com/sauravjaiswalsj) | [Sathyabama Institute of Science and Technology](http://www.sathyabama.ac.in/)
* [Foxxy](https://github.com/foxxydev) | ["Aurel Vlaicu" University of Arad](http://www.uav.ro)
* [Tejas Tank](https://github.com/majordwarf) | [Thakur College of Science and Commerce](http://tcsc.org.in/)
* [Sayan Mondal](https://github.com/sayanmondal2098) | [Techno India University , West Bengal](http://technoindiauniversity.ac.in)




Expand Down
72 changes: 72 additions & 0 deletions Quick sort/quicksort.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
#include<iostream>
using namespace std;
void swap1(int *a,int *b)
{

int temp=*a;
*a=*b;
*b=temp;
}

int partition1(int arr[],int start,int last)
{

int pivot=arr[last];
int current=start;
int i;
for( i=start;i<last;i++)
{
if(arr[i]<=pivot)
{

swap1(&arr[i],&arr[current]);
current++;
}



}

swap1(&arr[last],&arr[current]);

return current;
}


void quicksort(int arr[],int start,int last)
{
if(start<last)
{
int p_index=partition1(arr,start,last);
quicksort(arr,start,p_index-1);
quicksort(arr,p_index+1,last);


}



}

int main()
{
cout<<"ENTER SIZE"<<endl;
int n;
cin>>n;
int *arr;
arr=new int[n];
for(int i=0;i<n;i++)
{
cin>>arr[i];

}
int start=0;
int last=n-1;
quicksort(arr,start,last);
cout<<endl;
for(int i=0;i<n;i++)
{

cout<<arr[i]<<" ";
}
}
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
## Welcome to the Algorithms-Hacktoberfest by Fnplus

![fnplus](https://user-images.githubusercontent.com/25124428/47038568-6b991580-d19f-11e8-8e63-c1067fc04378.jpg)


This repository is a part of [ HacktoberFest -an event organised by DigitalOcean ](https://hacktoberfest.digitalocean.com/).
You are requested to create your profile using the above link to be a part of it.

Expand Down
55 changes: 55 additions & 0 deletions Stack.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
class Stack
{
static final int MAX = 1000;
int top;
int a[] = new int[MAX];

boolean isEmpty()
{
return (top < 0);
}
Stack()
{
top = -1;
}

boolean push(int x)
{
if (top >= (MAX-1))
{
System.out.println("Stack Overflow");
return false;
}
else
{
a[++top] = x;
System.out.println(x + " pushed into stack");
return true;
}
}

int pop()
{
if (top < 0)
{
System.out.println("Stack Underflow");
return 0;
}
else
{
int x = a[top--];
return x;
}
}
}
class Main
{
public static void main(String args[])
{
Stack s = new Stack();
s.push(10);
s.push(20);
s.push(30);
System.out.println(s.pop() + " Popped from stack");
}
}
82 changes: 82 additions & 0 deletions binary search/binarysearch.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
#include<iostream>
using namespace std;
///elements in array should be sorted
bool binarysearch(int arr[],int num,int low,int high)
{
int flag=0;
int mid;
if(low<=high)
{

mid=(low+high)/2;
if(arr[mid]<num)
{
low=mid+1;

}
else
{
high=mid-1;
}
if(num==arr[mid])
{
flag=1;
return true;

}
binarysearch(arr,num,low,high);
}
else
{

return false;
}
}

int main()
{
int n;
cout<<"Enter size"<<endl;
cin>>n;
int *arr;
arr=new int[n];
for(int i=0;i<n;i++)
{

cin>>arr[i];
}

for(int i=0;i<n;i++)
{
for(int j=i+1;j<n;j++)
{

if(arr[i]>arr[j])
{
int temp=arr[j];
arr[j]=arr[i];
arr[i]=temp;


}
}

}
int num;
cout<<"Enter num you want to search in an array"<<endl;
cin>>num;
int low=0;
int high=n-1;
if(binarysearch(arr,num,low,high)==true)
{
cout<<"ELEMNET FOUND"<<endl;

}
else
{

cout<<"ELEMNET NOT FOUND"<<endl;
}

return 0;
}
42 changes: 42 additions & 0 deletions binary_search/binarysearch.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#include<iostream>
#include<conio.h>
#include<algorithm>

int binary_search(int A[],int f,int l,int num)
{int mid;
mid=(f+l)/2;
if(num==A[mid])
return mid;

elseif(num>A[mid])
{binary_search(A,mid+1,l,num);}

elseif(num<A[mid])
{binary_search(A,f,mid-1,num);

else
return(-1);
}

int main()
{int a[100],n,d,x;
cout<<"how many numbers?";
cin>>n;

cout<<"enter numbers";
for(int i=0;i<n;i++)
cin>>a[i];

sort(a,a+n);

cout<<"Enter the number you wish to search";
cin>>d;

x=binary_search(a,0,n-1,d);

if(x!=-1)
cout<<"number is at "<<x+1<<"position";
else
cout<<"number not found";
return 0;
}
51 changes: 51 additions & 0 deletions binary_search/clang/Binary_Search.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@

#include <stdio.h>
#include <stdlib.h>
void sort(int *data, int n) {
int i, j, temp;
for (i = 1; i < n; i++) {
temp = data[i];
for (j = i; j > 0 && data[j-1] > temp; j--) {
data[j] = data[j-1];
}
data[j] = temp;
}
}

int main() {
int i, high, low, mid, n, *data, element, ch = 1;
printf("Binary Search Example:\n");
printf("Enter the number of entries:");
scanf("%d", &n);

data = (int *)malloc(sizeof (int) * n);
for (i = 0; i < n; i++) {
scanf("%d", &data[i]);
}
sort(data, n);
printf("After sorting:");
for (i = 0; i < n; i++)
printf("%3d ", data[i]);
printf("\n");
while (ch) {
printf("Enter the data to be searched:");
scanf("%d", &element);
low = 0, high = n-1;
while (low <= high) {
mid = (high + low) / 2;
if (data[mid] < element)
low = mid + 1;
else if (data[mid] > element)
high = mid - 1;
else {
printf("Search element %d found "
"at index %d\n", element, mid);
break;
}
}
printf("Searched element is not available\n");
printf("Do you wanna continue search(1/0):");
scanf("%d", &ch);
}
return 0;
}
Loading

0 comments on commit 375df2d

Please sign in to comment.