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

bubblesort whole #11

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions Algorithms/C/Bubblesort.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#include<stdio.h>

int main(){

int count, temp, i, j, number[30];

printf("How many numbers are u going to enter?: ");
scanf("%d",&count);

printf("Enter %d numbers: ",count);

for(i=0;i<count;i++)
scanf("%d",&number[i]);

/* This is the main logic of bubble sort algorithm
*/
for(i=count-2;i>=0;i--){
for(j=0;j<=i;j++){
if(number[j]>number[j+1]){
temp=number[j];
number[j]=number[j+1];
number[j+1]=temp;
}
}
}

printf("Sorted elements: ");
for(i=0;i<count;i++)
printf(" %d",number[i]);

return 0;
}
52 changes: 52 additions & 0 deletions Data-Strucutres/C/Stack.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
#include<stdio.h>
#include<conio.h>
#include<stdlib.h>

#define MAX_SIZE 5

int main() {
int item, choice, i;
int arr_stack[MAX_SIZE];
int top = 0;
int exit = 1;

printf("\nthis is a c program for stack operation");
printf("\nSimple Stack Example - Array");
do {
printf("\n\nnStack Main Menu");

printf("\n1.Push \n2.Pop \n3.Display \nOthers to exit");
printf("\nEnter Your Choice : ");
scanf("%d", &choice);
switch (choice) {
case 1:
if (top == MAX_SIZE)
printf("\n## Stack is Full!");
else {
printf("\nEnter The Value to be pushed : ");
scanf("%d", &item);
printf("\n## Position : %d , Pushed Value : %d ", top, item);
arr_stack[top++] = item;
}
break;
case 2:
if (top == 0)
printf("\n## Stack is Empty!");
else {
--top;
printf("\n## Position : %d , Popped Value : %d ", top, arr_stack[top]);
}
break;
case 3:
printf("\n## Stack Size : %d ", top);
for (i = (top - 1); i >= 0; i--)
printf("\n## Position : %d , Value : %d ", i, arr_stack[i]);
break;
default:
exit = 0;
break;
}
} while (exit);

return 0;
}