forked from akkupy/codeDump
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request akkupy#163 from IRENE260/main
Merge.c
- Loading branch information
Showing
4 changed files
with
360 additions
and
0 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,97 @@ | ||
#include<stdio.h> | ||
|
||
int a[50]; | ||
|
||
int main(){ | ||
|
||
int n,j,size,l1,u1,l2,u2,i,k; printf("Enter size of array:\n"); | ||
|
||
scanf("%d",&n); | ||
|
||
printf("Enter values:\n"); | ||
|
||
for(i=0;i<n;i++) { | ||
|
||
scanf("%d",&a[i]); | ||
|
||
} | ||
|
||
size =1; | ||
|
||
while(size<n){ | ||
|
||
l1=0; | ||
|
||
while(l1+size<n){ | ||
|
||
u1=l1+size-1; | ||
|
||
l2=l1+size; | ||
|
||
u2=l2+size-1; | ||
|
||
if(u2>=n) | ||
|
||
u2=n-1; | ||
|
||
int a1[u1-l1],a2[u2-l2]; | ||
|
||
for(i=0;i<=u1-l1;i++) | ||
|
||
a1[i]=a[l1+i]; | ||
|
||
for(j=0;j<=u2-l2;j++) | ||
|
||
a2[j]=a[l2+j]; | ||
|
||
i=0;j=0;k=l1; | ||
|
||
while(i<=u1-l1 && j<=u2-l2){ | ||
|
||
if(a1[i]<a2[j]) | ||
|
||
a[k++]=a1[i++]; | ||
|
||
else | ||
|
||
a[k++]=a2[j++]; | ||
|
||
|
||
|
||
} | ||
|
||
while(i<=u1-l1) | ||
|
||
a[k++]=a1[i++]; | ||
|
||
while(j<=u2-l2) | ||
|
||
a[k++]=a2[j++]; | ||
|
||
l1=u2+1; | ||
|
||
} | ||
|
||
size=size*2; | ||
|
||
} | ||
|
||
printf("Sorted Values:\n"); | ||
|
||
for(j=0;j<n;j++){ | ||
|
||
printf("%d\t",a[j]); | ||
|
||
} | ||
|
||
return 0; | ||
|
||
} | ||
|
||
Footer | ||
|
||
© 2022 GitHub, Inc. | ||
|
||
Footer navigation | ||
|
||
Ter |
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,81 @@ | ||
#include<stdio.h> | ||
|
||
int main() | ||
|
||
{ | ||
|
||
int n,s,l,c,i,count; printf("Enter total number of blocks in the disk:"); | ||
|
||
scanf("%d",&n); | ||
|
||
int a[n]; | ||
|
||
for(i=0;i<n;i++) | ||
|
||
{ | ||
|
||
a[i]=0; | ||
|
||
} | ||
|
||
do{ | ||
|
||
count=0; | ||
|
||
printf("Enter starting block and length of file:"); | ||
|
||
scanf("%d%d",&s,&l); | ||
|
||
for(i=s;i<(s+l);i++) | ||
|
||
{ | ||
|
||
if(a[i]==0) | ||
|
||
{ | ||
|
||
count++; | ||
|
||
} | ||
|
||
} | ||
|
||
if(count==l) | ||
|
||
{ | ||
|
||
for(i=s;i<(s+l);i++) | ||
|
||
{ | ||
|
||
a[i]=1; | ||
|
||
} | ||
|
||
printf("File Allocated\n"); | ||
|
||
} | ||
|
||
else | ||
|
||
{ | ||
|
||
printf("File Not Allocated\n"); | ||
|
||
} | ||
|
||
printf("Do you want to continue?(1.yes/0.No):"); | ||
|
||
scanf("%d",&c); | ||
|
||
}while(c!=0); | ||
|
||
return 0; | ||
|
||
} | ||
|
||
Footer | ||
|
||
© 2022 GitHub, Inc. | ||
|
||
Footer navigation |
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,107 @@ | ||
#include<stdio.h> | ||
|
||
void simplemerge(int x[] , int l , int s , int r ) | ||
|
||
{ | ||
|
||
int temp[30], k=0, i=l, j=s ; | ||
|
||
while(i<s && j<=r) | ||
|
||
{ | ||
|
||
if(x[i]<x[j]) | ||
|
||
temp[k++]=x[i++]; | ||
|
||
else | ||
|
||
temp[k++]=x[j++]; | ||
|
||
} | ||
|
||
while(i<s) | ||
|
||
temp[k++]=x[i++]; | ||
|
||
while(j<=r) | ||
|
||
temp[k++]=x[j++]; | ||
|
||
for(i=l, j=0; j<k; ) | ||
|
||
x[i++]=temp[j++]; | ||
|
||
} | ||
|
||
void mergesort(int a[] , int l , int r) | ||
|
||
{ | ||
|
||
int m; | ||
|
||
if(l<r) | ||
|
||
{ | ||
|
||
m=(l+r)/2; | ||
|
||
mergesort(a,l,m); | ||
|
||
mergesort(a,(m+1),r); | ||
|
||
simplemerge(a, l , (m+1), r); | ||
|
||
} | ||
|
||
} | ||
|
||
void main() | ||
|
||
{ | ||
|
||
int a[50], n , i ; | ||
|
||
printf("Enter the no of elements: "); | ||
|
||
scanf("%d",&n); | ||
|
||
printf("Enter the elements : \n"); | ||
|
||
for(i=0;i<n;i++) | ||
|
||
{ | ||
|
||
scanf("%d",&a[i]); | ||
|
||
} | ||
|
||
mergesort(a,0,(n-1)); | ||
|
||
printf(" sorted array is : "); | ||
|
||
for(i=0;i<n;i++){ | ||
|
||
printf("%d",a[i]); | ||
|
||
if(i!=n-1) | ||
|
||
printf(" , "); | ||
|
||
} | ||
|
||
} | ||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
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,75 @@ | ||
#include<stdio.h> | ||
|
||
int main() | ||
|
||
{ | ||
|
||
int n,s,l,c,i,count; printf("Enter total number of blocks in the disk:"); | ||
|
||
scanf("%d",&n); | ||
|
||
int a[n]; | ||
|
||
for(i=0;i<n;i++) | ||
|
||
{ | ||
|
||
a[i]=0; | ||
|
||
} | ||
|
||
do{ | ||
|
||
count=0; | ||
|
||
printf("Enter starting block and length of file:"); | ||
|
||
scanf("%d%d",&s,&l); | ||
|
||
for(i=s;i<(s+l);i++) | ||
|
||
{ | ||
|
||
if(a[i]==0) | ||
|
||
{ | ||
|
||
count++; | ||
|
||
} | ||
|
||
} | ||
|
||
if(count==l) | ||
|
||
{ | ||
|
||
for(i=s;i<(s+l);i++) | ||
|
||
{ | ||
|
||
a[i]=1; | ||
|
||
} | ||
|
||
printf("File Allocated\n"); | ||
|
||
} | ||
|
||
else | ||
|
||
{ | ||
|
||
printf("File Not Allocated\n"); | ||
|
||
} | ||
|
||
printf("Do you want to continue?(1.yes/0.No):"); | ||
|
||
scanf("%d",&c); | ||
|
||
}while(c!=0); | ||
|
||
return 0; | ||
|
||
} |