단일 체인 테이블 -- - 반복 설정, 반복 반전, 반복 인쇄
5697 단어 싱글 체인 테이블
/*
* 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);
}
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
단일 체인 테이블 -- - 반복 설정, 반복 반전, 반복 인쇄텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.