단일 체인 테이블 -- - 반복 설정, 반복 반전, 반복 인쇄

/*

*    auther: Try86

*    time:2012/9/25 13:14

*    dec: : , , 

*/



#include <stdio.h>

#include <stdlib.h>

#include <assert.h>



typedef struct list                 // 

{

   int data;

   struct list *p_next;

}List;



int main(void)

{

   int num = 0;                    // 

   List *head = NULL;              // 

   List *p_cur = NULL;

   void build_list(List **head, List *p_cur, int *pnum);   
void list_reverse(List **head, List *p_cur, List *p_nt, int *pnum); void print(List *ptr); build_list(&head, p_cur, &num); assert(NULL != head); // list_reverse(&head, head, head->p_next, &num); print(head); return 0; } // void build_list(List **head, List *p_cur, int *pnum) { int num; List *ptr = NULL; if (scanf("%d", &num) && num > 0) { ++(*pnum); if ((ptr = (List *)malloc(sizeof(List))) != NULL) { ptr->data = num; ptr->p_next = NULL; if (NULL == *head) { *head = ptr; p_cur = ptr; p_cur->p_next = ptr->p_next; } else { p_cur->p_next = ptr; p_cur = p_cur->p_next; } build_list(head, p_cur, pnum); } } } // void list_reverse(List **head, List *p_cur, List *p_nt, int *pnum) { if (NULL == p_nt) { *head = p_cur; --(*pnum); return ; } list_reverse(head, p_cur->p_next, p_nt->p_next, pnum); p_nt->p_next = p_cur; --(*pnum); if (0 == *pnum) { p_cur->p_next = NULL; } } // void print(List *ptr) { if (NULL != ptr) { printf("%d\t", ptr->data); } else { return ; } print(ptr->p_next); }

좋은 웹페이지 즐겨찾기