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

codes need to be added #1

Open
adityanjr opened this issue Nov 13, 2019 · 7 comments
Open

codes need to be added #1

adityanjr opened this issue Nov 13, 2019 · 7 comments
Labels

Comments

@adityanjr
Copy link
Owner

choose the right folder to add your codes..

@adityanjr adityanjr added help wanted Extra attention is needed good first issue Good for newcomers labels Nov 13, 2019
@vaibh289
Copy link

vaibh289 commented Oct 1, 2020

#include
#include <math.h>
using namespace std;
int heapSize;

void buildMaxHeap(int[],int);

void maxHeapify(int ptr[], int i, int s)
{
int l = 2i + 1;
int r = 2
i + 2;
int largest = i;
if((ptr[l]>ptr[largest]) && l<s)
largest = l;

if((ptr[r]>ptr[largest]) && r<s)
    largest = r;

if(largest != i)
{
    swap(ptr[i], ptr[largest]);
    maxHeapify(ptr, largest, s);
}

}

void buildMaxHeap(int ptr[], int s)
{
for(int i=(s/2)-1; i>=0; i--)
maxHeapify(ptr, i, s);

for (int i=s-1; i>=0; i--)
{
	swap(ptr[0], ptr[i]);
	maxHeapify(ptr, 0, i);
}

}

void heapSort(int ptr[], int s)
{
buildMaxHeap(ptr, s);
}

int main()
{
int * ptr, n;
cout << "Enter the size of the Array: ";
cin >> n;
ptr = new int[n];
if(ptr == NULL)
{
cout << "Insufficient Memory.";
}
cout<< "Enter the elements:\n";
for(int i=0; i<n; i++)
{
cout<<"["<<i<<"]:";
cin >> ptr[i];
}
heapSort(ptr, n);
cout << "\nSorted Array: \n";
for(int i=0; i<n; i++)
{
cout << ptr[i] << " ";
}
return 0;
}

1 similar comment
@vaibh289
Copy link

vaibh289 commented Oct 1, 2020

#include
#include <math.h>
using namespace std;
int heapSize;

void buildMaxHeap(int[],int);

void maxHeapify(int ptr[], int i, int s)
{
int l = 2i + 1;
int r = 2
i + 2;
int largest = i;
if((ptr[l]>ptr[largest]) && l<s)
largest = l;

if((ptr[r]>ptr[largest]) && r<s)
    largest = r;

if(largest != i)
{
    swap(ptr[i], ptr[largest]);
    maxHeapify(ptr, largest, s);
}

}

void buildMaxHeap(int ptr[], int s)
{
for(int i=(s/2)-1; i>=0; i--)
maxHeapify(ptr, i, s);

for (int i=s-1; i>=0; i--)
{
	swap(ptr[0], ptr[i]);
	maxHeapify(ptr, 0, i);
}

}

void heapSort(int ptr[], int s)
{
buildMaxHeap(ptr, s);
}

int main()
{
int * ptr, n;
cout << "Enter the size of the Array: ";
cin >> n;
ptr = new int[n];
if(ptr == NULL)
{
cout << "Insufficient Memory.";
}
cout<< "Enter the elements:\n";
for(int i=0; i<n; i++)
{
cout<<"["<<i<<"]:";
cin >> ptr[i];
}
heapSort(ptr, n);
cout << "\nSorted Array: \n";
for(int i=0; i<n; i++)
{
cout << ptr[i] << " ";
}
return 0;
}

@adityanjr
Copy link
Owner Author

add in the repo.

adityanjr pushed a commit that referenced this issue Oct 13, 2020
@srisrinu1
Copy link

Aditya can I add solutions to binarysearch.io problems. Is this acceptable?

@adityanjr
Copy link
Owner Author

@srisrinu1 Yes, just add them into a seperate folder.

@adityanjr adityanjr added hacktober-fest and removed help wanted Extra attention is needed labels Oct 4, 2021
@vivek-0110
Copy link

hii @adityanjr can i add some codes on sorting algorithm? kindly assign me the issue then.Thank you

@adityanjr
Copy link
Owner Author

@vivek-0110 Look through the folder and add if it is not already there. just make pull request, i'll review.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants