Skip to content
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
60 changes: 60 additions & 0 deletions Adithya_Qsort.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
#include<stdio.h>
struct point //the variable is a structure which stores the value of the abcissa and the ordinate
{
int a,b;
};
void swap(point&t1, point&t2) //for swapping
{
point temp;
temp=t1;
t1=t2;
t2=temp;
}
int partition(point w[1000], int low, int high) //used to find the position to divide the array into 2 about a pivot element
{
int k;
point pivot = w[high]; //The pivot is chosen as the last element of the array
int i = low-1;

for(k= low; k<=high-1; k++)
{
if(w[k].a < pivot.a || (w[k].a == pivot.a && w[k].b<=pivot.b ) ) //Element smaller than the pivot are moved forward
{
i++;
swap(w[k],w[i]);

}

}
swap(w[i+1],w[high]); //This brings the pivot element to the right postion in the ordered array
return (i+1); //returns the position about which the array is to be divided
}
void quicksort(point w[1000], int low, int high)
{
if(low<high)
{
int j= partition(w,low,high);
quicksort(w,low,j-1); //Uses recursion and two divided arrays undergo the same process
quicksort(w,j+1,high); //the old pivot element is not included in these 2 new arrays
}
}

int main() //The main function
{
point t[1000];
int n,i;
printf("Enter the number of pairs");
scanf("%d",&n);
printf("Enter the pairs");
for(i=0;i<n;i++)
{
scanf("%d %d",&t[i].a,&t[i].b);
}
quicksort(t,0,n-1);

for(i=0;i<n;i++)
{
printf("%d,%d ",t[i].a,t[i].b);
}
return 0;
}
29 changes: 29 additions & 0 deletions Adithya_bubble.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#include<stdio.h>
int main()
{
int n,j,i,a[100];
printf("Enter the number of elements");
scanf("%d",&n);
printf("Enter the elements");
for(i=0;i<n;i++)
{
scanf("%d",&a[i]);
}
for(i=0;i<n-1;i++)
{
for(j=0;j<n-i-1;j++)
{
if(a[j]>a[j+1])
{
int temp=a[j];
a[j]=a[j+1];
a[j+1]=temp;
}
}
}
printf("The ordered pair is \n");
for(i=0;i<n;i++)
{printf("%d ",a[i]);}
return 0;

}
36 changes: 36 additions & 0 deletions Adithya_modular exponentiation.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#include<stdio.h>
#include<conio.h>
int rem (int c, int d,int t, int& res)
{
d=d%c;
if(t==1)
{
res=res*d;
}
d=d*d;
return d;

}
int main()
{
int i,k,a,b,b1,c,bin[100],ans,res=1,m=1;
printf("Enter a,b,c as a^b mod c");
scanf("%d %d %d",&a,&b,&c);
b1=b;
i=0;

while(b1>0)
{
bin[i]=b1%2;
b1=b1/2;
i++;
}
for(k=0;k<i;k++)
{
a=rem(c,a,bin[k],res);
}
ans=res%c;
printf("The result is %d",ans);
return 0;

}