C语言数据结构 link 链表反转的实现
链表反转,示例如下:
偶数个输入:a->b->c->d->e->f
偶数个输出:e->f->c->d->a->b
or
奇数个输入:a->b->c->d->e->f->g
偶数个输出:g->e->f->c->d->a->b
#include <stdio.h>
#include <malloc.h>
#include <stdlib.h>
/************** start of stack *************/
#define STACK_SIZE 1024
char stack[STACK_SIZE];
int top = 0;
void push(char ch){
stack[top] = ch;
top++;
}
char pop(){
top--;
return stack[top];
}
int isempty(){
return 0 == top;
}
void test_stack(){
push('a');
push('b');
push('c');
push('d');
while(!isempty()){
printf("pop ch: %cn", pop());
}
}
/************** end of stack *************/
struct _node{
char data;
struct _node *next;
};
typedef struct _node node, *plink;
plink init_link(){
plink pl;
pl = (plink)malloc(sizeof(node));
// check malloc success or not
if(NULL == pl) {
printf("malloc memory fail...");
return NULL;
}
// init link head
pl->data = '