Posts

Showing posts from July 20, 2018

Selection Sort

Program In C++:-                       // Selection Sort #include <iostream> using namespace std; void SelectionSort(int a[],int n) {  int i,j,temp,large;  for(i=n-1;i>0;i--)  {  large=0;  for(j=0;j<=i;j++)  if(a[j]>a[large])  large=j;  temp=a[i];  a[i]=a[large];  a[large]=temp;  }  cout<<"\nDisplaying the sorted values:";  for(i=0;i<n;i++)  cout<<"\n"<<a[i]; } int main() {  int n;  cout<<"Enter the size of array:";  cin>>n;  int arr[n];  cout<<"Enter the values of array:\n";  for(int i=0;i<n;i++)  cin>>arr[i];  SelectionSort(arr,n); } /* output Enter the size of array:3 Enter the values of array: 1 9 2 Displaying the sorted values: 1 2 9 */

Insertion Sort

Program In C++:-                                                                         //Insertion Sort #include <iostream> using namespace std; void InsertionSort(int a[],int n) {  int i,j,temp;  for(j=1;j<n;j++)  {  temp=a[j];  i=j;  while(i>0 && a[i-1]>=temp)  {  a[i]=a[i-1];  i--;  }  a[i]=temp;  }  cout<<"Displaying the values:";  for(i=0;i<n;i++)  cout<<"\n"<<a[i]; } int main() {  int n;  cout<<"Enter the size of array:";  cin>>n;  int a[n];  cout<<"Enter the values in Array:\n";  for(int i=0;i<n;i++)  cin>>a[i];  InsertionSort(a,n); } /* Output Enter the size of array:3 Enter the values in Array: 5 1 4 Displaying the values: 1 4 5 */

Web Technology Practical

  (1)Frames: HTML frames are used to divide your browser window into multiple sections where each section can load a separate HTML document. To use frames on a page we use <frameset> tag instead of <body> tag. The <frameset> tag defines, how to divide the window into frames. The rows attribute of <frameset> tag defines horizontal frames and cols attribute defines vertical frames. Each frame is indicated by <frame> tag and it defines which HTML document shall open into the frame. (2)HTML Redirection:- The redirection is done with the meta refresh in the head section. The link in the body section for fallback purposes. HTML redirection used to redirect current page to another page or resources directly on clicking the link. (3)Redirection Through Server Side language PHP is a server side scripting language; the redirect script will be executed on your server and not on your visitors browser. This is a non-client/browser dependent approach. The P

Quick Sort

Program In C++:-                          //Quick Sort #include<iostream> using namespace std; int a[25]; int Partition(int l,int h) {     int pivot,i,j;     pivot=a[l];     i=l;     j=h;     while(i<j)     {         while(a[i]<=pivot && i<=h)         {             i++;         }         while(a[j]>pivot && j>=l)         {             j--;         }         if(i<j)         {             int x=a[i];             a[i]=a[j];             a[j]=x;         }     }     a[l]=a[j];     a[j]=pivot;     return j; } void quicksort(int l,int h) {     if(l<h)     {         int q=Partition(l,h);         quicksort(l,q-1);         quicksort(q+1,h);     } } int main() {     int i, n;     cout<<"enter size of array"<<endl;     cin>>n;     cout<<"enter elements in array"<<endl;     for(i=0;i<n;i++)     {         cin>>a[i];     }     quicksort(0,n-1);    

Prim's Algorithm

Program In C:-                            // Prim's Algorithm #include<stdio.h> #include<stdlib.h> #define infinity 9999 #define MAX 20 int G[MAX][MAX],spanning[MAX][MAX],n; int prims(); int main() {     int i,j,total_cost;     printf("nter number of vertices:");     scanf("%d",&n);     printf("\nenter the adjacency matrix:\n");     for(i=0;i<n;i++)         for(j=0;j<n;j++)             scanf("%d",&G[i][j]);     total_cost=prims();     printf("\nspanning tree matrix:\n");     for(i=0;i<n;i++)     {         printf("\n");         for(j=0;j<n;j++)             printf("%d\t",spanning[i][j]);     }     printf("\n\notal cost of spanning tree is=%d",total_cost);     return 0; } int prims() {     int cost[MAX][MAX];     int u,v,min_distance,distance[MAX],from[MAX];     int visited[MAX],no_of_edges,i,min_cost,j;     //create cost[][] matrix,spannin

Merge Sort

Program In C++:-                          // Merge Sort #include<iostream> using namespace std; int a[20],b[20]; void Merge(int,int,int); void mergesort(int l,int h) {     if(l<h)     {         int mid=(l+h)/2;         mergesort(l,mid);         mergesort(mid+1,h);         Merge(l,mid,h);     } } void Merge(int l,int mid,int h) {     int i,j,k;     i=l;     j=mid+1;     k=l;     while(i<=mid && j<=h)     {         if(a[i]<=a[j])         {             b[k]=a[i];             i++;         }         else         {             b[k]=a[j];             j++;         }         k++;     }     while(i<=mid)     {         b[k]=a[i];         i++;         k++;     }     while(j<=h)     {         b[k]=a[j];         j++;         k++;     }     for(i=l;i<=h;i++)     {         a[i]=b[i];     } } int main() {     int n;     cout<<"enter size of array"<<endl;     cin>>n;     cout<<

Maxheap Sort

Program In C:-                          //Maxheap Sort #include <stdio.h> #include <stdlib.h> #define MAX 20 void maxheapify(int *, int, int); int* buildmaxheap(int *, int); void main() {     int i, t, n; int *a = calloc(MAX, sizeof(int));     int *m = calloc(MAX, sizeof(int));     printf("enter no of elements in the array\n");     scanf("%d", &n);     printf("enter the array\n");     for (i = 0; i < n; i++) {         scanf("%d", &a[i]);     }     m = buildmaxheap(a, n);     printf("the heap is\n");     for (t = 0; t < n; t++) {         printf("%d\n", m[t]);     } } int* buildmaxheap(int a[], int n) {     int heapsize = n;     int j;     for (j = n/2; j >= 0; j--) {         maxheapify(a, j, heapsize);     }     return a; } void maxheapify(int a[], int i, int heapsize) {     int temp, largest, left, right, k;     left = (2*i+1);     right = ((2*i)+2);     if (