-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4557738
commit d429d7e
Showing
15 changed files
with
172 additions
and
94 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
*.exe |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
{ | ||
"files.associations": { | ||
"BeadSort.C": "cpp", | ||
"BubbleSort.C": "cpp", | ||
"CocktailSort.C": "cpp", | ||
"CockTailSort2.C": "cpp", | ||
"GnomeSort.C": "cpp", | ||
"HeapSort2.C": "cpp", | ||
"InsertionSort.C": "cpp", | ||
"MatrixSort.C": "cpp", | ||
"Merge2SortedArray.C": "cpp", | ||
"MergeSort2.C": "cpp", | ||
"MergeSort3.C": "cpp", | ||
"MergeSort4.C": "cpp", | ||
"OddEvenSort.C": "cpp", | ||
"PanCakeSort.C": "cpp", | ||
"PigeonHoleSort.C": "cpp", | ||
"QuickSort.C": "cpp", | ||
"QuickSort2.C": "cpp", | ||
"SelectionSort.C": "cpp", | ||
"ShellSort.C": "cpp" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,87 +1,93 @@ | ||
#include<stdio.h> | ||
#include<stdlib.h> | ||
|
||
//Created in College library (March 5th) | ||
|
||
void heapsort(int list[],int n) { | ||
int step=1; | ||
for(int k=n; k>=2; k--) { | ||
int temp=list[1]; | ||
list[1]=list[k]; | ||
list[k]=temp; | ||
int i=1; | ||
int value =list[1]; | ||
int j=2; | ||
|
||
if((j+1)<k) | ||
if(list[j+1]>list[j]) | ||
#include <stdio.h> | ||
#include <stdlib.h> | ||
|
||
// Created in College library (March 5th) | ||
|
||
void heapsort(int list[], int n) | ||
{ | ||
int step = 1; | ||
for (int k = n; k >= 2; k--) | ||
{ | ||
int temp = list[1]; | ||
list[1] = list[k]; | ||
list[k] = temp; | ||
int i = 1; | ||
int value = list[1]; | ||
int j = 2; | ||
|
||
if ((j + 1) < k) | ||
if (list[j + 1] > list[j]) | ||
j++; | ||
|
||
while((j<=(k-1)) && (list[j]>value)) | ||
{ | ||
list[i]=list[j]; | ||
i=j; | ||
j=2*i; | ||
while ((j <= (k - 1)) && (list[j] > value)) | ||
{ | ||
list[i] = list[j]; | ||
i = j; | ||
j = 2 * i; | ||
|
||
if((j+1)<k) | ||
if(list[j+1]>list[j]) | ||
if ((j + 1) < k) | ||
if (list[j + 1] > list[j]) | ||
j++; | ||
else if(j>n) | ||
j=n; | ||
else if (j > n) | ||
j = n; | ||
|
||
list[i]=value; | ||
list[i] = value; | ||
} | ||
|
||
printf("\nStep = %d ",step); | ||
printf("\nStep = %d ", step); | ||
step++; | ||
for(int p=1; p<=n; p++) | ||
printf(" %d",list[p]); | ||
for (int p = 1; p <= n; p++) | ||
printf(" %d", list[p]); | ||
} | ||
|
||
} | ||
|
||
void createHeap(int list[],int n) { | ||
for(int k=2; k<=n; k++) | ||
void createHeap(int list[], int n) | ||
{ | ||
for (int k = 2; k <= n; k++) | ||
{ | ||
int i=k; | ||
int temp=list[k]; | ||
int j=i/2; | ||
int i = k; | ||
int temp = list[k]; | ||
int j = i / 2; | ||
|
||
while((i>1) && (temp>list[j])) | ||
while ((i > 1) && (temp > list[j])) | ||
{ | ||
list[i]=list[j]; | ||
i=j; | ||
j=i/2; | ||
if(j<1) | ||
j=1; | ||
list[i] = list[j]; | ||
i = j; | ||
j = i / 2; | ||
if (j < 1) | ||
j = 1; | ||
} | ||
list[i]=temp; | ||
list[i] = temp; | ||
} | ||
} | ||
|
||
void display(int list[],int n) { | ||
for(int i=1; i<=n; i++) | ||
printf(" %d",list[i]); | ||
void display(int list[], int n) | ||
{ | ||
for (int i = 1; i <= n; i++) | ||
printf(" %d", list[i]); | ||
} | ||
|
||
int main(void) { | ||
int main(void) | ||
{ | ||
int list[20]; | ||
int n; | ||
printf("enter the size of the list: "); | ||
scanf("%d",&n); | ||
scanf("%d", &n); | ||
|
||
for (int i = 1; i <= n; i++) | ||
list[i] = rand() % 100; | ||
|
||
for(int i=1; i<=n; i++) | ||
list[i]=rand()%100; | ||
printf("\nlist:\n"); | ||
display(list,n); | ||
display(list, n); | ||
|
||
createHeap(list, n); | ||
|
||
createHeap(list,n); | ||
printf("\nHeap:\n"); | ||
display(list,n); | ||
display(list, n); | ||
printf("\n"); | ||
|
||
heapsort(list,n); | ||
heapsort(list, n); | ||
|
||
printf("\nSorted List: \n"); | ||
display(list,n); | ||
display(list, n); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.