Skip to content

Commit

Permalink
Create sortingnewmethod.c
Browse files Browse the repository at this point in the history
  • Loading branch information
Vaibhavtech2006 authored Oct 30, 2024
1 parent e5dad3f commit 588ab77
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions data_structures/sortingnewmethod.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#include <stdio.h>

void bubbleSort(int arr[], int n) {
for (int i = 0; i < n - 1; i++) {
for (int j = 0; j < n - i - 1; j++) {
if (arr[j] > arr[j + 1]) {
int temp = arr[j];
arr[j] = arr[j + 1];
arr[j + 1] = temp;
}
}
}
}

int main() {
int arr[] = {64, 25, 12, 22, 11};
int n = sizeof(arr) / sizeof(arr[0]);
bubbleSort(arr, n);
printf("Sorted array: ");
for (int i = 0; i < n; i++) printf("%d ", arr[i]);
return 0;
}

0 comments on commit 588ab77

Please sign in to comment.