0

这些是功能

//printList for Debugging
void printList(letterListT *head){
    letterListT *temp = head;
    while(temp != NULL){
        printf("%c ", temp->letter);
    temp = temp->nxt;
    }
}  

//Add the Specified Letter by Creating a New Node in the Letter List defined
void addLetter(letterListT *letListHead, char letter){
    letterListT *newNode;
    newNode = (letterListT *)malloc(sizeof(letterListT));

    newNode->letter = letter;

    newNode->nxt = letListHead->nxt;
    letListHead->nxt = newNode;
}

这些主要是:

unusedLetList = (letterListT *)malloc(sizeof(letterListT));
unusedLetList->nxt = NULL;

for(i=122; i>=97; i--){ //ascii codes for z to a
addLetter(unusedLetList, i);
}

//printlists Test
printList(unusedLetList);

这是输出...

p a b c d e f g h i j k l m n o p q r s t u v w x y z 

我的问题是……这个“p”是从哪里来的?!

4

1 回答 1

5

The list head node.

unusedLetList = (letterListT *)malloc(sizeof(letterListT));
unusedLetList->nxt = NULL;

You create a head node here, and then add each letter after the head node. The head node has an uninitialized ->letter field. It could be anything; it happens to be p.

于 2012-12-16T21:49:39.517 回答