Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

can you convert this python code to c language code?? code : def sufcmp(Z,i,j):

ID: 3572374 • Letter: C

Question

can you convert this python code to c language code??

code :

def sufcmp(Z,i,j):
n = len(Z)-i
m = len(Z)-j
k = min(n,m)
for o in range(k):
if Z[i+o]<Z[j+o]:
return -1
if Z[i+o]>Z[j+o]:
return 1

if n<m:
return -1
else:
return 1

def sufsort(Z):

print(Z)
N = len(Z)

if N <= 0 or N > 30:
print("length error")
return

for i in range(N):
if not (Z[i]=='0' or Z[i]=='1' or Z[i]=='2'):
print("composition error")
return

y = [];
for i in range(N):
y.append(i);


for i in range(N,0,-1):
for j in range(1,i):
k = sufcmp(Z,y[j-1],y[j])
if k > 0:
t = y[j-1]
y[j-1]=y[j]
y[j]=t

print("sorted suffixes:")
for i in range(N):
print(Z[y[i]:N])

You try sufsort("22010100")

Please help!

Explanation / Answer

#include<stdio.h>

#include<conio.h>

#include<string.h>

int compare(Z,i,j);

void main()

{

int n,m,k;

char Z[30];

int i,j,N;

Z={2,2,0,1,0,1,0,0};

N=strlen(Z);

if((N<=0)||(N>30))

{

printf("length error");

}

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

{

if((Z[i]=='0')||(Z[i]=='1')||(Z[i]=='2'))

{}

else

printf("comosite error");

}

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

{

y[i]=i;

}

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

{

for(j=1;j<N;j++)

{

k=compare(Z,y[j-1],y[j]);

if(k>0)

{

t = y[j-1];

y[j-1]=y[j];

y[j]=t;

}

}

}

printf("sorted suffix");

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

{

printf("%d",Z[y[i]]);

}

}

int compare(char Z,int i,int j)

{

int n,o,m,k,i,j;

n=strlen(Z)-i;

m=strlen(Z)-j;

if(n<m)

k=n;

else

k=m;

for(o=0;o<k;o++)

{

if(Z[i+o]<Z[j+o])

return -1;

if(Z[i+o]>Z[j+o])

return 1;

}

  

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Chat Now And Get Quote