answersLogoWhite

0

AllQ&AStudy Guides
Best answer

/* Bubble sort:

code snippet only

nos to be sorted are in the array named 'n' of size 'N'

for(int i=0;i<N-1;i++)

for(int j=i+1;j<N-1-i;j++)

if(n[j]>n[j+1])

swap(n[j],n[j+1]);

*/

/*

insertion sort

int v,j;

for(int i=1;i<N;i++)

{

v=n[j];

for(int j=i-1;j>0&&n[j]>v;j--)

n[j+1]=n[j];

n[j+1]=v;

}

*/

This answer is:
Related answers

/* Bubble sort:

code snippet only

nos to be sorted are in the array named 'n' of size 'N'

for(int i=0;i<N-1;i++)

for(int j=i+1;j<N-1-i;j++)

if(n[j]>n[j+1])

swap(n[j],n[j+1]);

*/

/*

insertion sort

int v,j;

for(int i=1;i<N;i++)

{

v=n[j];

for(int j=i-1;j>0&&n[j]>v;j--)

n[j+1]=n[j];

n[j+1]=v;

}

*/

View page

2j+1/j+5 = 1

Multiply all terms by j+5 to eliminate the fraction:

2j+1 = j+5

2j-j = 5-1

j = 4

View page

Roman numeral converter: J=1

1 is j in roman numeral, its hard believe it but it is true

View page

#include<stdio.h> #include<string.h> #include<conio.h> int count=0; char arr1[20],arr2[20]; int main() { int j; arr1[0]=1; arr1[1]='\0'; int flag=3; for(j=3;j>=-1;j--) printf(" "); printf("1\n"); while(flag>=0) { for(j=3;j>=count;j--) printf(" "); arr2[0]=arr1[0]; arr2[strlen(arr1)]=arr1[strlen(arr1)-1]; for(j=1;j<=(strlen(arr1)-1);j++) arr2[j]=arr1[j]+arr1[j-1]; arr2[strlen(arr1)+1]='\0'; for(j=0;j<strlen(arr2);j++) printf("%d ",arr2[j]); for(j=0;j<=strlen(arr2);j++) arr1[j]=arr2[j]; flag--; count++; printf("\n\n"); } getch(); }

View page
Conversion of a Regular Expression to NFA Algorithm Source code C programmingCS342 Compiler Lab Source code Algorithm C Programming

#include

#include

void main()

{

char reg[20];

int q[20][3],i,j,len,a,b;

clrscr();

for(a=0;a<20;a++)

{

for(b=0;b<3;b++)

{

q[a][b]=0;

}

}

printf("Regular expression: \n");

scanf("%s",reg);

len=strlen(reg);

i=0;

j=1;

while(i

{

if(reg[i]=='a'&®[i+1]!='/'&®[i+1]!='*')

{

q[j][0]=j+1;

j++;

}

if(reg[i]=='b'&®[i+1]!='/'&®[i+1]!='*')

{

q[j][1]=j+1;

j++;

}

if(reg[i]=='e'&®[i+1]!='/'&®[i+1]!='*')

{

q[j][2]=j+1;

j++;

}

if(reg[i]=='a'&®[i+1]=='/'&®[i+2]=='b')

{

q[j][2]=((j+1)*10)+(j+3);

j++;

q[j][0]=j+1;

j++;

q[j][2]=j+3;

j++;

q[j][1]=j+1;

j++;

q[j][2]=j+1;

j++;

i=i+2;

}

if(reg[i]=='b'&®[i+1]=='/'&®[i+2]=='a')

{

q[j][2]=((j+1)*10)+(j+3);

j++;

q[j][1]=j+1;

j++;

q[j][2]=j+3;

j++;

q[j][0]=j+1;

j++;

q[j][2]=j+1;

j++;

i=i+2;

}

if(reg[i]=='a'&®[i+1]=='*')

{

q[j][2]=((j+1)*10)+(j+3);

j++;

q[j][0]=j+1;

j++;

q[j][2]=((j+1)*10)+(j-1);

j++;

}

if(reg[i]=='b'&®[i+1]=='*')

{

q[j][2]=((j+1)*10)+(j+3);

j++;

q[j][1]=j+1;

j++;

q[j][2]=((j+1)*10)+(j-1);

j++;

}

if(reg[i]==')'&®[i+1]=='*')

{

q[0][2]=((j+1)*10)+1;

q[j][2]=((j+1)*10)+1;

j++;

}

i++;

}

printf("Transition function \n");

for(i=0;i<=j;i++)

{

if(q[i][0]!=0)

printf("\n q[%d,a]-->%d",i,q[i][0]);

if(q[i][1]!=0)

printf("\n q[%d,b]-->%d",i,q[i][1]);

if(q[i][2]!=0)

{

if(q[i][2]<10)

printf("\n q[%d,e]-->%d",i,q[i][2]);

else

printf("\n q[%d,e]-->%d & %d",i,q[i][2]/10,q[i][2]%10);

}

}

getch();

}

View page
Featured study guide
📓
See all Study Guides
✍️
Create a Study Guide
Search results