From fab9f4db346ce1313b315ea7c92269040f83920d Mon Sep 17 00:00:00 2001 From: 11fenil11 <47125158+11fenil11@users.noreply.github.com> Date: Sat, 10 Aug 2019 13:41:38 +0530 Subject: [PATCH] Add files via upload --- 1_ada_iterative.cpp | 17 +++++ 1_ada_recursion.cpp | 24 +++++++ 2_adaBubbleSort.cpp | 80 +++++++++++++++++++++++ 2_adaBucketsort.cpp | 80 +++++++++++++++++++++++ 2_adaSelectionSort.cpp | 56 ++++++++++++++++ 2_ada_insertionsort.cpp | 52 +++++++++++++++ 3_pr_code.cpp | 72 +++++++++++++++++++++ 3_practical_shapes.cpp | 67 +++++++++++++++++++ 4_ada_binarysearch.cpp | 106 ++++++++++++++++++++++++++++++ 4_dda_cg.cpp | 116 +++++++++++++++++++++++++++++++++ 5_bresenham.cpp | 122 +++++++++++++++++++++++++++++++++++ 6_final.cpp | 81 +++++++++++++++++++++++ 7_mid_point_elipse_pro.cpp | 86 ++++++++++++++++++++++++ 8_floodfill_boundaryfill.cpp | 93 ++++++++++++++++++++++++++ Heap_sort.cpp | 96 +++++++++++++++++++++++++++ bucket_sort.cpp | 70 ++++++++++++++++++++ 16 files changed, 1218 insertions(+) create mode 100644 1_ada_iterative.cpp create mode 100644 1_ada_recursion.cpp create mode 100644 2_adaBubbleSort.cpp create mode 100644 2_adaBucketsort.cpp create mode 100644 2_adaSelectionSort.cpp create mode 100644 2_ada_insertionsort.cpp create mode 100644 3_pr_code.cpp create mode 100644 3_practical_shapes.cpp create mode 100644 4_ada_binarysearch.cpp create mode 100644 4_dda_cg.cpp create mode 100644 5_bresenham.cpp create mode 100644 6_final.cpp create mode 100644 7_mid_point_elipse_pro.cpp create mode 100644 8_floodfill_boundaryfill.cpp create mode 100644 Heap_sort.cpp create mode 100644 bucket_sort.cpp diff --git a/1_ada_iterative.cpp b/1_ada_iterative.cpp new file mode 100644 index 0000000..9d10ca5 --- /dev/null +++ b/1_ada_iterative.cpp @@ -0,0 +1,17 @@ +#include +using namespace std; + +int main() +{ + int n,ans=1; + cout<<"Enter Number to find it's factorial = "; + cin>>n; + + for(int i=n;i>0;i--) + { + ans=ans*i; + } + cout< +using namespace std; + +int fact(int n) +{ + if(n==0 || n==1) + { + return 1; + } + else + return n*fact(n-1); +} + +int main() +{ + int n; + cout<<"Enter Number to find it's factorial = "; + cin>>n; + + int ans=fact(n); + cout< +#include +using namespace std; + +int count_pass=1; +vector sorrrt(vector a1) +{ + + int temp,i,j,flag; + for(i=0;i<(a1.size())-count_pass;i++) + { + j=i+1; + if(a1[i]>a1[j]) + { + temp=a1[j]; + a1[j]=a1[i]; + a1[i]=temp; + } + else + { + flag=1; + } + } + count_pass++; + return a1; +} +int main() +{ + vector a1; + int n,i,p; + cout<<"Enter Size ::"; + cin>>n; + for(i=0;i>x; + a1.push_back(x); + } + for(i=0;i +#include +#include +using namespace std; + +void bucketsort() +{ + vector v[10]; + int i,j,n,num; + float arr[100]; + cout<<"Enter How many values you want to enter : "; + cin>>num; + for(i=0;i>arr[i]; + } + + for(i=0;i bucketsort(vector v, int n) +//{ +// vector a[10]; +// for(int i=0;i v; + int i,j,n; +// cout<<"Enter Number:"; +// cin>>n; +// for(i=0;i>x; +// v.push_back(x); +// } + bucketsort(); +} diff --git a/2_adaSelectionSort.cpp b/2_adaSelectionSort.cpp new file mode 100644 index 0000000..7b9081b --- /dev/null +++ b/2_adaSelectionSort.cpp @@ -0,0 +1,56 @@ +#include +#include +using namespace std; + +vector soort(vector a,int n) +{ + int i,j,temp,min,minj; + for(i=0;ia[j]) + { + // min=a[j]; + minj=j; + } + } + if(minj!=i) + { + temp=a[minj]; + a[minj]=a[i]; + a[i]=temp; + } + for(int k=0;k v; + int n,i,j; + cout<<"Enter Numbers:"; + cin>>n; + for(i=0;i>x; + v.push_back(x); + } + for(i=0;i +#include +using namespace std; + +vector insertionsort(vector v,int n) +{ + int i,j; + for(i=1;i=0 && tmp v; + int i,j,n; + cout<<"Enter Number:"; + cin>>n; + for(i=0;i>x; + v.push_back(x); + } + v=insertionsort(v,n); + for(i=0;i +main() +{ + initwindow(800,800,"Practicle 3"); + int x1=getmaxx(); + int y1=getmaxy(); + //take point in 4th quadrant. + line(0,0,x1,0);//top horizontal line + line(x1/3,0,x1/3,y1);//1st verticle line + line((2*x1)/3,0,(2*x1)/3,y1);//2nd verticle line + line(x1,0,x1,y1);//right most verticle line + line(0,0,0,y1);//left most verticle line + line(0,y1/3,x1,y1/3);//1st horizontal line + line(0,(2*y1)/3,x1,(2*y1)/3);//2nd horizontal line + line(0,y1,x1,y1);//Bottom horizontal line + setfillstyle(1,4); + circle(x1/2,y1/2,x1/12); + floodfill((x1/2)+1,(y1/2)+1,15); + + setfillstyle(1,6); + pieslice(x1/6,y1/3,60,120,(x1/3)-20); + floodfill((x1/6),(y1/6),15); + + setfillstyle(7,14); + //bar((2*x1/3)+10,(2*y1/3)+10,x1-10,y1-10); + rectangle((2*x1/3)+10,(2*y1/3)+10,x1-10,y1-10); + floodfill((2*x1/3)+20,(2*y1/3)+20,15); + + setfillstyle(3,5); + bar(20,(2*y1/3)+20,(x1/3)-20,y1-20); + rectangle(20,(2*y1/3)+20,(x1/3)-20,y1-20); + floodfill(23,(2*y1/30)+30,15); + + setfillstyle(6,7); + ellipse(x1/2,y1/6,0,360,x1/6,y1/12); + floodfill(x1/2,y1/6,15); + + arc(x1/2,(2*y1/3)+(y1/6),0,180,x1/12); + + line(2*x1/3,y1/6,x1,y1/6); + + setfillstyle(1,8); + floodfill((5*x1/6),(y1/2),15); + line((5*x1/6),(y1/3)+20,(2*x1/3)+20,(2*y1/3)-20); + line((5*x1/6),(y1/3)+20,x1-20,(2*y1/3)-20); + line((2*x1/3)+20,(2*y1/3)-20,(x1-20),(2*y1/3)-20); + setfillstyle(1,6); + //floodfill(168,426,15); + bar(20,(y1/3)+(y1/15),(x1/3)-20,(y1/3)+(2*y1/15)); + rectangle(20,(y1/3)+(y1/15),(x1/3)-20,(y1/3)+(2*y1/15)); + setfillstyle(1,15); + //floodfill(98,440,15); + bar(20,(y1/3)+(2*y1/15),(x1/3)-20,(y1/3)+(3*y1/15)); + rectangle(20,(y1/3)+(2*y1/15),(x1/3)-20,(y1/3)+(3*y1/15)); + setfillstyle(1,2); + //floodfill(170,509,15); + bar(20,(y1/3)+(3*y1/15),(x1/3)-20,(y1/3)+(4*y1/15)); + rectangle(20,(y1/3)+(3*y1/15),(x1/3)-20,(y1/3)+(4*y1/15)); + + setbkcolor(1); + setcolor(2); + setfillstyle(1,3); + //floodfill(x1/6,y1/2,15); + circle(x1/6,(y1/2),(y1/30)); + //rectangle(1120,720,1980,1080); + getch(); +} diff --git a/3_practical_shapes.cpp b/3_practical_shapes.cpp new file mode 100644 index 0000000..2558a53 --- /dev/null +++ b/3_practical_shapes.cpp @@ -0,0 +1,67 @@ +#include +main() +{ + initwindow(800,800,"Practicle 3"); + int x1=getmaxx(); + int y1=getmaxy(); + //take point in 4th quadrant. + line(0,0,x1,0); + line(x1/3,0,x1/3,y1);//1st verticle line + line((2*x1)/3,0,(2*x1)/3,y1);//2nd verticle line + line(x1,0,x1,y1); + line(0,0,0,y1); + line(0,y1/3,x1,y1/3);//1st horizontal line + line(0,(2*y1)/3,x1,(2*y1)/3);//2nd horizontal line + line(0,y1,x1,y1); + setfillstyle(1,4); + circle(x1/2,y1/2,x1/12); + floodfill((x1/2)+1,(y1/2)+1,15); + + setfillstyle(1,6); + pieslice(x1/6,y1/3,60,120,(x1/3)-20); + floodfill((x1/6),(y1/6),15); + + setfillstyle(7,14); + //bar((2*x1/3)+10,(2*y1/3)+10,x1-10,y1-10); + rectangle((2*x1/3)+10,(2*y1/3)+10,x1-10,y1-10); + floodfill((2*x1/3)+20,(2*y1/3)+20,15); + + setfillstyle(3,5); + bar(20,(2*y1/3)+20,(x1/3)-20,y1-20); + rectangle(20,(2*y1/3)+20,(x1/3)-20,y1-20); + floodfill(23,(2*y1/30)+30,15); + + setfillstyle(6,7); + ellipse(x1/2,y1/6,0,360,x1/6,y1/12); + floodfill(x1/2,y1/6,15); + + arc(x1/2,(2*y1/3)+(y1/6),0,180,x1/12); + + line(2*x1/3,y1/6,x1,y1/6); + + setfillstyle(1,8); + floodfill((5*x1/6),(y1/2),15); + line((5*x1/6),(y1/3)+20,(2*x1/3)+20,(2*y1/3)-20); + line((5*x1/6),(y1/3)+20,x1-20,(2*y1/3)-20); + line((2*x1/3)+20,(2*y1/3)-20,(x1-20),(2*y1/3)-20); + setfillstyle(1,6); + //floodfill(168,426,15); + bar(20,(y1/3)+(y1/15),(x1/3)-20,(y1/3)+(2*y1/15)); + rectangle(20,(y1/3)+(y1/15),(x1/3)-20,(y1/3)+(2*y1/15)); + setfillstyle(1,15); + //floodfill(98,440,15); + bar(20,(y1/3)+(2*y1/15),(x1/3)-20,(y1/3)+(3*y1/15)); + rectangle(20,(y1/3)+(2*y1/15),(x1/3)-20,(y1/3)+(3*y1/15)); + setfillstyle(1,2); + //floodfill(170,509,15); + bar(20,(y1/3)+(3*y1/15),(x1/3)-20,(y1/3)+(4*y1/15)); + rectangle(20,(y1/3)+(3*y1/15),(x1/3)-20,(y1/3)+(4*y1/15)); + + setbkcolor(1); + setcolor(2); + setfillstyle(1,3); + //floodfill(x1/6,y1/2,15); + circle(x1/6,(y1/2),(y1/30)); + //rectangle(1120,720,1980,1080); + getch(); +} diff --git a/4_ada_binarysearch.cpp b/4_ada_binarysearch.cpp new file mode 100644 index 0000000..07d9214 --- /dev/null +++ b/4_ada_binarysearch.cpp @@ -0,0 +1,106 @@ +#include +#include +#include +using namespace std; + +int binarysearch(vector &v,int i,int j,int n,int x) +{ + if(x>v[n-1] || x &v,int n,int x) +{ + for(int i=1;i v; + int n,i; + cout<<"Enter Number:"; + cin>>n; + for(i=0;i>option; + int x; + cout<<"Enter the number you want to search: "; + cin>>x; + + switch(option) + { + case 1: + sort(v.begin(),v.end()); + cout<<"Sorted Array "; + for(i=0;i +#include +#include +using namespace std; + +main() +{ + + float x1,x2,y2,y1; + int xp,yp; + cout<<"Enter x1= "; + cin>>x1; + cout<<"Enter y1= "; + cin>>y1; + cout<<"Enter X2= "; + cin>>x2; + cout<<"Enter y2= "; + cin>>y2; + if(x20 && (y2-y1)>0 ) + { + if(m<=1) + { + while(xp!=x2 && yp!=y2) + { + x=x1+1.00; + y=y1+m; + xp=round(x); + yp=round(y); + cout<<"xp="<0 && (y2-y1)>0 ) + { + if(m<=1) + { + while(xp!=x2 && yp!=y2) + { + if(po<0) + { + po=po+2*dy; + x=x1+1; + y=y1; + xp=round(x); + yp=round(y); + cout<<"x="<=0) + { + po=po+2*dy-2*dx; + x=x1+1; + y=y1+1; + xp=round(x); + yp=round(y); + cout<<"x="<1) + { + while(xp!=x2 && yp!=y2) + { + if(po<0) + { + po=po+2*dx; + x=x1+1; + y=y1; + xp=round(x); + yp=round(y); + cout<<"x="<=0) + { + po=po+2*dx-2*dy; + x=x1+1; + y=y1+1; + xp=round(x); + yp=round(y); + cout<<"x="< +#include +using namespace std; + +int main() +{ + int r; + cout<<"Enter Radius:"; + cin>>r; + int xc,yc; + cout<<"Enter Center Point: "; + cin>>xc>>yc; + int po=1-r; + int x=0,y=r; + + if(r<=0 || (xc+r)>=800 ||(yc+r)>=800 ||(yc-r)<=0 || (xc-r)<=0) + { + cout<<"Error:Enter Right Value For Radius Or Center Points.\n(1)May be you entered negative or zero value for radius! \n(2)May be your combination of center points and radius leads circle outside of our window!\n"; + main(); + } + else + { + initwindow(800,800); + putpixel(xc,yc,15); + putpixel(xc+x,yc+y,15); + putpixel(xc+x,yc-y,15); + putpixel(xc+y,yc+x,15); + putpixel(xc-y,yc+x,15); + while(x>xc>>yc; + int po=(ry*ry)-((rx*rx)*ry)+((rx*rx)/4); + int x=0,y=ry; + + if(rx<0 ||ry<0 || (xc+rx)>800 ||(yc+ry)>800 ||(yc-ry)<0 || (xc-rx)<0) + { + cout<<"Error:Enter Right Value For Radius Or Center Points.\n(1)May be you entered negative or zero value for radius! \n(2)May be your combination of center points and radius leads circle outside of our window!\n"; + main(); + } + else + { + initwindow(800,800); + putpixel(xc,yc,15); + putpixel(xc+x,yc+y,15); + putpixel(xc+x,yc-y,15); + putpixel(xc+rx,yc+x,15); + putpixel(xc-rx,yc+x,15); + while((ry*ry*x)<(rx*rx*y)) + { + if(po<0) + { + x=x+1; + po=po+(2*x*ry*ry)+(ry*ry); + //cout<<"Dicision Parameter:"<(500,500)\n"; + cout<<"Enter X & Y Cordinates="; + cin>>x>>y; + int fcol=1; + int bcol=15; + int oldcol=0; + + int op; + cout<<" {--1--}PRESS 1 FOR FLOOD_FILL \n {--2--}PRESS 2 FOR BOUNDARY_FILL \n{--*--}Enter Your Choice For Filling Color:"; + cin>>op; + initwindow(800,800,"FloodFill BoundaryFill"); + rectangle(300,300,500,500); + setfillstyle(SOLID_FILL,3); + bar(450,450,600,600); + rectangle(450,450,600,600); +// setfillstyle(SOLID_FILL,10); +// pieslice(330,350,330,30,50); + + switch(op) + { + case 1 : + cout<<"Enter Fill COLOR code"; + cin>>fcol; + cout<<"Enter Old Color"; + cin>>oldcol; + flood_fill(x,y,fcol,oldcol); + break; + + case 2 : + cout<<"Enter Fill COLOR code"; + cin>>fcol; + cout<<"Enter Boundary COLOR code"; + cin>>bcol; + boundary_fill(x,y,fcol,bcol); + break; + default : + cout<<"-------------ENTER VALID KEY!----------"; + } + + + + getch(); + return 0; +} diff --git a/Heap_sort.cpp b/Heap_sort.cpp new file mode 100644 index 0000000..d646d75 --- /dev/null +++ b/Heap_sort.cpp @@ -0,0 +1,96 @@ +#include +#include +#include +using namespace std; + +void sortofheap(vector &v,int &n) +{ + for(int i=((n/2)-1);i>=0;i--) + { + if(((2*i)+2)v[(2*i)+1]) + { + if(v[i]>v[(2*i)+2]) + { + v[i]=v[i]; + } + else + { + int temp; + temp= v[i]; + v[i]=v[(2*i)+2]; + v[(2*i)+2]=temp; + } + } + else + { + if(v[(2*i)+1]>v[(2*i)+2]) + { + int temp; + temp= v[i]; + v[i]=v[(2*i)+1]; + v[(2*i)+1]=temp; + } + else + { + int temp; + temp= v[i]; + v[i]=v[(2*i)+2]; + v[(2*i)+2]=temp; + } + } + } + else + { + if(v[i] &v,int &n) +{ + while(n>1) + { + int temp; + temp= v[0]; + v[0]=v[n-1]; + v[n-1]=temp; + n=n-1; + sortofheap(v,n); + } +} +int main() +{ + vector v; + int i,flag=1; + cout<<"1)Add More Value?Flag=1 \n2) Otherwise Flag=0."<>x; + v.push_back(x); + cout<<"Flag="; + cin>>flag; + } + cout<<"STARTING VECTOR: "; + for(i=0;i +#include +#include +using namespace std; + +void enterD(vector &v) +{ + int n; + cout<<"Enter Number of Elements:"; + cin>>n; + + for(int i=0;i>x; + v.push_back(x); + } +} +void display(vector &v) +{ + for(int i=0;i &v) +{ + vector > b(10); + //vector c(10,0); + vector a; + int i,j,k; + cout<<"B.size()"<