DS AllLab Program
DS AllLab Program
Write a program to check whether the given matrix is sparse or not and represent
the matrix in sparse representation and determine the transpose of sparse
representation.
#include<stdio.h>
#include<conio.h>
void main()
{
int i,j,temp,n,p,a[20];
clrscr();
printf("\t\t\t\t---Insertion Sort---\n\n\n");
printf("Enter the size of the array\n");
scanf("%d",&n);
printf("Enter the elements\n");
for(i=0;i<n;i++)
{
scanf("%d",&a[i]);
}
for(i=1;i<n;i++)
{
for(j=i-1;j>=0;j--)
{
if(a[j]>a[j+1])
{
temp=a[j+1];
a[j+1]=a[j];
a[j]=temp;
}
}
}
printf("the sorted array\n");
for(i=0;i<n;i++)
{
printf("%d\n",a[i]);
}
getch();
}
#include<stdio.h>
#include<conio.h>
int number[25];
void quicksort(int first,int last)
{
int i,j,pivot,temp;
clrscr();
if(first<last)
{
pivot=first;
i=first;
j=last;
while(i<j)
{
while (number[i]<=number[pivot]&&i<last)
i++;
while (number[j]>number[pivot])
j--;
if(i<j)
{
temp=number[i];
number[i]=number[j];
number[j]=temp;
}
}
temp=number[pivot];
number[pivot]=number[j];
number[j]=temp;
quicksort(first,j-1);
quicksort(j+1,last);
}
}
void main()
{
int i,n;
printf("Enter the size of the array\n");
scanf("%d",&n);
printf("Enter the elements into the array\n");
for(i=0;i<n;i++)
{
scanf("%d",&number[i]);
}
quicksort(0,n-1);
printf("sorted array");
for(i=0;i<n;i++)
{
printf(" %d",number[i]);
}
getch();
}
#include<stdio.h>
#include<conio.h>
void shellsort(int a[], int num)
{
int gap,j,k,temp;
for(gap=num/2;gap>0;gap=gap/2)
{
for(j=gap;j<num;j++)
{
for(k=j-gap;k>=0;k=k-gap)
{
if(a[k+gap]>=a[k])
{
break;
}
else
{
temp=a[k];
a[k]=a[k+gap];
a[k+gap]=temp;
}
}
}
}
}
void main()
{
int a[20],k,i,num;
printf("Enter the number of elements\n");
scanf("%d",&num);
printf("Enter the elements\n");
for(k=0;k<num;k++)
{
scanf("%d",&a[k]);
}
shellsort(a,num);
printf("sorted array is\n");
for(k=0;i<num;k++)
{
printf("%d",a[k]);
}
getch();
}
5. Develop a program for STACK that performs following primitive operations: push,
pop and display