Skip to content

Commit 34cf1a1

Browse files
Pattern 1
1 parent a232f93 commit 34cf1a1

File tree

4 files changed

+44
-3
lines changed

4 files changed

+44
-3
lines changed

pattern_1.c

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#include<stdio.h>
2+
int n;
3+
4+
int main(){
5+
printf("Enter no. of rows : ");
6+
scanf("%d",&n);
7+
int i,j,c;
8+
for(i=1;i<=n;i++){
9+
c=n-i+1;
10+
for(j=1;j<=i;j++)
11+
printf("%d",c++);
12+
for(int k=i+1;k<=n;k++)
13+
printf("%d",n);
14+
printf("\n");
15+
}
16+
return 0;
17+
}

pattern_1.exe

40.5 KB
Binary file not shown.

quick_sort.c

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ void swap(int *a, int *b){
1111
}
1212

1313
int partition(int low, int high) {
14-
14+
/*
1515
// select the rightmost element as pivot
1616
int pivot = a[high];
1717
@@ -36,9 +36,33 @@ int partition(int low, int high) {
3636
swap(&a[i + 1], &a[high]);
3737
3838
// return the partition point
39-
return (i + 1);
40-
}
39+
return (i + 1);*/
4140

41+
int i,j,t,flag=1,pos=low;
42+
while(flag == 1){
43+
for(i=high;i>pos;i--){
44+
flag = 0;
45+
if(a[pos]>a[i]){
46+
swap(&a[pos], &a[i]);
47+
pos=i;
48+
flag=1;
49+
break;
50+
}
51+
}
52+
if(flag == 1){
53+
for(i=low;i<pos;i++){
54+
flag = 0;
55+
if(a[pos]<a[i]){
56+
swap(&a[pos],&a[i]);
57+
pos = i;
58+
flag = 1;
59+
break;
60+
}
61+
}
62+
}
63+
}
64+
return pos;
65+
}
4266
void Quicksort(int lb, int ub){
4367
if(lb<ub){
4468
pivot=partition(lb,ub);

quick_sort.exe

494 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)