알파벳순으로 단어를 추가 할 addWord 부분을 반환 할 수 있습니까? 시도했지만 작동하지 않았습니다. C 프로그래밍에서 매우 새로 운 것입니다. 사실, 일주일이 지난 지금부터 작업 중입니다. 그러나 나는 문제가 될 수 없다.C에서 알파벳순으로 노드 추가
typedef struct NODE {
char *str;
int count;
struct NODE *pNext;
} NODE;
void addWord(char *word)
{
NODE *pCounter = NULL;
NODE *pLast = NULL;
if(pStart == NULL) // pstart is globally defined pStart=NULL;
{
pStart = createWordCounter(word);
return;
}
/* If the word is in the list, increment its count */
pCounter = pStart;
while(pCounter != NULL)
{
if(strcmp(word, pCounter->str) == 0)
{
++pCounter->count;
return;
}
pLast = pCounter;
pCounter = pCounter->pNext;
}
/* Word is not in the list, add it */
pLast->pNext = createWord(word);
}
NODE* createWord(char *word)
{
NODE *pCounter = NULL;
pCounter = (NODE*)malloc(sizeof(NODE));
pCounter->str = (char*)malloc(strlen(word)+1);
strcpy(pCounter->str, word);
pCounter->count = 1;
pCounter->pNext = NULL;
return pCounter;
}
나는이 부분을 시도하지만 result.Here
void addWord(char *word)
{
NODE *pCounter = NULL;
NODE *pLast = NULL;
NODE *pNew = NULL;
if(pStart == NULL)
{
pStart = createWordCounter(word);
return;
}
/* If the word is in the list, increment its count */
pCounter = pStart;
while(pCounter != NULL)
{
if(strcmp(word, pCounter->str) == 0)
{
++pCounter->count;
return;
}
pLast = pCounter;
pCounter = pCounter->pNext;
}
while(pCounter != NULL){
if(strcmp(word,pCounter->str)<0){
pNew =createWordCounter(word);
pLast->pNext = pNew ;
pNew->pNext = pCounter;
pCounter = pLast->pNext;
}
else{
pNew=createWordCounter(word);
pNew->pNext=pCounter;
pLast->pNext=pNew;
}
}
죄송합니다 우리는 당신을 위해 여기없는 시도 숙제. 특정 문제가 발생하면 도움을 드릴 수 있습니다. – rmi
특정 문제는 addWord 부분입니다. 알파벳으로 반환 할 수 없습니다. psudocode를 도울 수 있다고 생각하십니까? – user3546593
'작동하지 않음'이란 무엇을 의미합니까? 알파벳 순서로 추가하지만 알파벳 순서로 추가하지 않습니까? – rmi