-
Notifications
You must be signed in to change notification settings - Fork 4
/
SortingSubstringUsing.c
54 lines (54 loc) · 1.44 KB
/
SortingSubstringUsing.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#include <stdio.h>
#include <string.h>
void main()
{
char *s="cate";
int substringListIter=0;
int length=strlen(s);
int i,j,k;
int numSubstring=(length*(length+1))/2;
char substringList[numSubstring][length+1];
for(i=0;i<length;i++)
{
for(j=0;j<length-i;j++)
{
int sslen=(length-j-i);
int iter=0;
char substring[sslen];
for(k=i;k<length-j;k++)
{
printf("%c", s[k]);
substring[iter]=s[k];
substringList[substringListIter][iter]=s[k];
iter++;
}
substringList[substringListIter][iter]='\0';
printf("\t");
puts(substringList[substringListIter]);
substringListIter++;
printf("\n");
}
}
printf("Printing in alphabetical order");
printf("\n");
//printf("%d",substringListIter);
int l=substringListIter;
char temp[l];
for (int j=0; j<l-1; j++)
{
for (int i=j+1; i<l; i++)
{
if (strcmp(substringList[j],substringList[i]) > 0)
{
strcpy(temp,substringList[j]);
strcpy(substringList[j],substringList[i]);
strcpy(substringList[i], temp);
}
}
}
//printf("%s",(substringList[1]));
for (int i=0; i<l; i++)
{
printf("%s ",(substringList[i]));
}
}