Answer the question
In order to leave comments, you need to log in
How to solve the problem of sorting by counting an array of strings?
Please help me understand the task and its implementation.
Write a program that sorts an array of strings alphabetically using counting sort. Use pointers to strings.
There is some code found on the Internet, but it doesn’t really work, it doesn’t give errors, but a windows window appears, requiring you to debug or close the program.
PS I am writing in C, i.e. string cannot be used?
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main()
{
char a;
char a2;
int i, j, k;
char *mas, *mas2;
int *key;
*mas=a;
*mas2=a2;
*key=k;
int size=10;
i=0;
while (*(mas+i)!='\n')
{
gets(*(mas+i));
*(key+i)=0;
i++;
}
for (i=size-1;i>0;i--)
for (j=i-1;j>=0;j--)
if (strcmp(*(mas+i),*(mas+j))<0) key[j]++;
else key[i]++;
for (j=0;j<size;j++)
mas2[key[j]]=mas[j];
return 0;
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question