随笔分类 -  数据结构

二叉树的先序、中序、后序遍历和复制
摘要:// binary.h //#include"stack.h"char Getdata() {char data; cin>>data; return data;} //Getdatavoid CreateBiTree(BiTree &T)//建立二叉链表{char ch;ch=Getdata();if(ch=='#') T=NULL;else{T=new BiTNode;T->data=ch;CreateBiTree(T->lchild);CreateBiTree(T->rchild);}}void InOrder(B 阅读全文
posted @ 2013-05-05 16:53 向云武 阅读(1391) 评论(0) 推荐(0)
后缀表达式求值
摘要:// zzz.cpp //#include"zzz.h"void evaluation(string s){LinkStack S;InitStack(S);char ch;double a,b;istringstream iss(s);iss>>ch;while(ch!='#'){if(!OpMember(double(ch))) push_stack(S,(double)ch-'0');else{pop_stack(S,a); pop_stack(S,b);push_stack(S,operatorr(b,ch,a));}is 阅读全文
posted @ 2013-05-03 17:09 向云武 阅读(221) 评论(0) 推荐(0)
稀疏矩阵相加
摘要:// aaa.h //#include<iostream>using namespace std;typedef struct {int i,j,e;}Triple;typedef struct{Triple data[30];int mu,nu,tu;}TSMtatrix;TSMtatrix Init(TSMtatrix &M)//初始化三元组顺序表{M.mu=5;M.nu=5;M.tu=0;M.data[0].i=0;M.data[0].j=0;M.data[0].e=1;return M;}TSMtatrix houyi(TSMtatrix &M,int k) 阅读全文
posted @ 2013-04-29 11:43 向云武 阅读(308) 评论(0) 推荐(0)
划分子集问题
摘要:// bbb.h //#include<iostream>using namespace std;typedef struct {int * elem;int front;int rear;int queuesize;}sqQueue;void init_sq(sqQueue &q, int maxsize){q.elem=new int[maxsize-1];q.queuesize=maxsize;q.front=q.rear=0;}bool delete_sq(sqQueue &q , int & e){int m=0;for(int i=0;i< 阅读全文
posted @ 2013-04-29 11:34 向云武 阅读(360) 评论(0) 推荐(0)
求取后缀表达式
摘要:// hhh.cpp //#include"hhh.h"void transform(char *suffix , string s){LinkStack S;InitStack(S);char ch,c;push_stack(S,'#');istringstream iss(s);iss>>ch;int k=0; //cout<<"iss:"<<ch<<endl;while(!stackempty(S)){if(!OpMember(ch)) suffix[k++]=ch;//cout< 阅读全文
posted @ 2013-04-29 11:17 向云武 阅读(247) 评论(0) 推荐(0)
背包问题
摘要://stack.h//#include<iostream>using namespace std;typedef int ElemType;typedef struct NodeType{ElemType data;NodeType *next;}NodeType,*LinkStack; void InitStack(LinkStack &S) //初始化栈{S=NULL;} //InitListbool pop_stack(LinkStack &S, ElemType &e) //出栈{NodeType *p;p=new NodeType;if(S){p= 阅读全文
posted @ 2013-04-29 11:09 向云武 阅读(89) 评论(0) 推荐(0)