C 언어 단일 체인 테이블 - 시작

2536 단어 C 언어

#include <stdio.h> 
#include <malloc.h> 

#define TRUE  1
#define FALSE 0

/*
*         ,   node
*/
struct node {
        int no;
        char name[20];
        struct node * next;
};

/*
*              
*/
int exists (struct node * q, int no) {
        while(q) {
                if (q->no == no) {
                        return TRUE;
                }
                q = q->next;
        }
        return FALSE;
}


int main(int argc, char * argv[]) {
        
        /*            */
        struct node * head = NULL;
        struct node * p = NULL;
        struct node * q = NULL;
        
        /*    */
        p = (struct node *)malloc(sizeof(struct node));
        
        printf("     ,  -1    :");
        scanf("%d", &p->no);
        
        while (-1 != p->no) {
                printf("      %d     :", p->no);
                scanf("%s", p->name);
                printf("
"); /**/ if (NULL == head) { head = p; q = head; } else { q->next = p; q = p; } q->next = NULL; /**/ p = (struct node *)malloc(sizeof(struct node)); printf(" , -1 :"); scanf("%d", &p->no); while(exists(head, p->no)) { printf(" , :"); scanf("%d", &p->no); } } /* */ q = head; while(q) { printf("no is '%d' and name is '%s'
", q->no, q->name); q = q->next; } return 0; }

코드의 C 언어 네트워크 주소는 다음과 같습니다.
http://bbs.cyuyan.com.cn/thread-5276-1-1.html

좋은 웹페이지 즐겨찾기