1、2 将单向链表 reverse,如 ABCD 变成 DCBA,只能搜索链表一次。#include “stdio.h“#include “string.h“#include “stdlib.h“#define ElemType char#define STACK_INIT_SIZE 100#define STACKINITSIZE 10typedef struct nodeElemType data;struct node * next;Lnode,*LinkList;LinkList GreatLink(int n)LinkList p,q,List=NULL;ElemType e;int i
2、;for (i=0;idata=e;p-next=NULL;if(!List) List=p;else q-next=p;q=p;return List;void InsertLink(LinkList *l,LinkList q,int e)LinkList p;p=(LinkList)malloc(sizeof(Lnode);p-data=e;p-next=NULL;if(!*l) *l=p;else q-next=p;typedef structElemType *base;ElemType *top;int stack_size;sqStack;void InitStack(sqSta
3、ck *s)s-base=s-top=(ElemType *)malloc(STACK_INIT_SIZE*sizeof(ElemType);if(!s-base) exit(0);s-stack_size=STACK_INIT_SIZE;void Push(sqStack *s,int e)if(s-top-s-base=s-stack_size) s-base=(ElemType *)realloc(s-base,(s-stack_size+STACKINITSIZE)*sizeof(ElemType);if(!s-base) exit(0);s-top=s-base+s-stack_si
4、ze;s-stack_size=s-stack_size+STACKINITSIZE;*(s-top)=e;s-top+;void Pop(sqStack *s,ElemType *e)if(s-top=s-base) return;*e=*-(s-top);int StackLen(sqStack s)return(s.top-s.base);void main()LinkList l,q;sqStack s;ElemType e;int len;int i;InitStack(q=l=GreatLink(1);scanf(“%c“,while(e!=#)InsertLink(q=q-next;scanf(“%c“,q=l;printf(“the LinkList is“);while(q)Push(q=q-next;len=StackLen(s);for(i=0;ilen;i+)Pop(printf(“%c“,e);printf(“n“);