Step by step Algorithm: Start the Bit stuffing program
An input string is accepted from the user and saved in ‘a’.
In the program if consecutive 1’s for more than 5 bits, then a ‘0’ is passed after the fifth ‘1’.
This form is the bit stuffed number.
At the receiver side the added ‘0’ is removed and original string is restored
Finally it gives the unstuffed string
BIT Stuffing
In the stuffing process the data should be sent specified in step, whenever 5 consecutive ones come a zero should be appended. In the case of unstuffy check for zero after 5 consecutive ones and remove it . Thus we fount original information
Source Code in C programming CS1305- NETWORK LAB
#include<stdio.h>
main()
{ char a[10];
int count=0,i=0,j,l,k=0;
printf("Enter the input string");
scanf("%s",a);
L=strlen(a);
for(i=0;i<l;i++)
if(a[i]=='1')
{ k=i;
count=0;
while(a[k]=='1')
{ count+=1;
k++;
if(count==5)
{ for(j=l+1;j>k;j--)
{ a[j]=a[j-1];
} a[k]='0';
l++;
break;
}
i=k;
}
}
printf("\n The bitstuffed string is %s",a);
//getch();
k=0;
for(i=0;i<=l;i++)
{ if(a[i]=='1')
{
k=i;
count=0;
while(a[k]=='1')
{ count+=1;
k++;
if(count==5)
{
for(j=k;j<l+1;j++)
{
a[j]=a[j+1];
} l--;
a[l+1]='0';
break;
} }
i=k-1;
} }
printf("String after unstuffing %s\n",a);
}
Output CS1305- NETWORK LAB
Enter the input string 111111011
The bit stuffed string is 111110011
String after unstuffing is 11111011
Bit Stuffing in C Language Programming with Stuffed Number CS1305- NETWORK LAB
QUICK SORT Data Structure lab programming Algorithm Quick Sort
Quick sort Programming Source code it has the header file quick.h it contains void swap(int *x,int *y),void display(int A[],int n),void insertionsort(int A[],int n),int median(int A[],int left,int right),void quicksort(int A[],int left,int right) by using these function and there variable we can use in the main function of the program
“Quick.h” file
QUICK SORT Data Structure lab programming Algorithm in c / c++
#include<stdio.h>
#include<conio.h>
#define cutoff (3)
void swap(int *x,int *y)
{
int temp;
temp=*x;
*x=*y;
*y=temp;
}
void display(int A[],int n)
{
int i;
for(i=0;i<n;i++)
printf("%d\t",A[i]);
}
void insertionsort(int A[],int n)
{
int j,p,temp;
for(p=1;p<n;p++)
{
temp=A[p];
for(j=p;j>0&&A[j-1]>temp;j--)
A[j]=A[j-1];
A[j]=temp;
}
}
int median(int A[],int left,int right)
{
int center=(left+right)/2;
if(A[left]>A[center])
swap(&A[left],&A[center]);
if(A[left]>A[right])
swap(&A[left],&A[right]);
if(A[center]>A[right])
swap(&A[center],&A[right]);
if(A[left]<=A[center]<=A[right])
swap(&A[center],&A[right-1]);
return A[right-1];
}
void quicksort(int A[],int left,int right)
{
int i,j,pivot;
if(left+cutoff<=right)
{
pivot=median(A,left,right);
i=left;
j=right-1;
for(;;)
{
while(A[++i]<pivot)
{}
while(A[--j]>pivot)
{}
if(i<j)
swap(&A[i],&A[j]);
else
break;
}
swap(&A[i],&A[right-1]);
quicksort(A,left,i-1);
quicksort(A,i+1,right);
}
else
insertionsort(A+left,right-left+1);
}
“Quick.c” file
QUICK SORT Data Structure lab programming Algorithm in c c++
#include"quick.h"
void main()
{
int A[20],n,i;
clrscr();
printf("\n how many numbers do u want to sort:\t");
scanf("%d",&n);
printf("\n\n Enter the values");
for(i=0;i<n;i++)
{
printf("\n A[%d]\t",i);
scanf("%d",&A[i]);
}
quicksort(A,0,n-1);
display(A,n);
getch();
}
OUTPUT
QUICK SORT Data Structure lab Output in c c++
How many numbers do u want to sort: 5
Enter the values
A[0] 25
A[1] 10
A[2] 89
A[3] 65
A[4] 15
10 15 25 65 89
JNTU-HYD : 1,2,3,4 Years Regular/Supple (I&II Sem) May/June-2010 Papers (All Regulations & Branches)- Get Question Papers Before Exams.
Get Question Papers Before Exams.
B.Tech
1 st Year Regular/Supplementary Examinations Papers-June-2010 (All Regulations)
R09(Regular Exams Papers-June-2010)-All Branches
R07(Supplementary Exams Papers-June-2010)-All Branches
R05(Supplementary Exams Papers-June-2010)-All Branches
RR(Supplementary Exams Papers-June-2010)-All Branches
NR(Supplementary Exams Papers-June-2010)-All Branches
EDP Regular/Supple Papers (May/June-2010)-All Branches
2-1 Semester Supplementary Examinations Papers-June-2010 (All Regulations)
R07(Supplementary Exams Papers-June-2010)-All Branches
R05(Supplementary Exams Papers-June-2010)-All Branches
RR & RA(Supplementary Exams Papers-June-2010)-All Branches
NR(Supplementary Exams Papers-June-2010)-All Branches
2-2 Semester Regular/Supplementary Examinations Papers-May-2010 (All Regulations)
R07(Regular/Supplementary Exam Papers-May–2010)-All Branches
R05(Supplementary Exam Papers-May–2010)-All Branches
RR(Supplementary Exam Papers-May–2010)-All Branches
NR(Supplementary Exam Papers-May–2010)-All Branches
3-1 Semester Supplementary Examinations Papers-June-2010 (All Regulations)
R07(Supplementary Exams Papers-June-2010)-All Branches
R05(Supplementary Exams Papers-June-2010)-All Branches
RR(Supplementary Exams Papers-June-2010)-All Branches
NR(Supplementary Exams Papers-June-2010)-All Branches
3-2 Semester Regular/Supplementary Examinations Papers-May-2010 (All Regulations)
R07(Regular Exam Papers-May–2010)-All Branches
R05(Supplementary Exam Papers-May–2010)-All Branches
RR(Supplementary Exam Papers-May–2010)-All Branches
NR(Supplementary Exam Papers-May–2010)-All Branches
4-1 Semester Supplementary Examinations Papers-June-2010 (All Regulations)
R05(Supplementary Exams Papers-June-2010)-All Branches
RR(Supplementary Exams Papers-June-2010)-All Branches
NR(Supplementary Exams Papers-June-2010)-All Branches
4-2 Semester Regular/Supplementary Examinations Papers-May-2010 (All Regulations)
R05(Regular/Supplementary Exam Papers-May–2010)-All Branches
RR(Supplementary Exam Papers-May–2010)-All Branches