将单向链表reverse,如ABCD变成DCBA,只能搜索链表一次。.doc

上传人:ng****60 文档编号:2417199 上传时间:2019-05-12 格式:DOC 页数:3 大小:19.75KB
下载 相关 举报
将单向链表reverse,如ABCD变成DCBA,只能搜索链表一次。.doc_第1页
第1页 / 共3页
将单向链表reverse,如ABCD变成DCBA,只能搜索链表一次。.doc_第2页
第2页 / 共3页
将单向链表reverse,如ABCD变成DCBA,只能搜索链表一次。.doc_第3页
第3页 / 共3页
亲,该文档总共3页,全部预览完了,如果喜欢就下载吧!
资源描述

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“);

展开阅读全文
相关资源
相关搜索

当前位置:首页 > 教育教学资料库 > 精品笔记

Copyright © 2018-2021 Wenke99.com All rights reserved

工信部备案号浙ICP备20026746号-2  

公安局备案号:浙公网安备33038302330469号

本站为C2C交文档易平台,即用户上传的文档直接卖给下载用户,本站只是网络服务中间平台,所有原创文档下载所得归上传人所有,若您发现上传作品侵犯了您的权利,请立刻联系网站客服并提供证据,平台将在3个工作日内予以改正。