数据结构实现
来源:互联网 发布:在中国卖的好跑车知乎 编辑:程序博客网 时间:2024/05/29 19:41
链表实现
#include <iostream>#include <cstdlib>using namespace std;struct LNode{int data;LNode* next;};typedef LNode* LinkedList;void creatLinkList(LinkedList &L){L= (LinkedList)malloc(sizeof(LNode));L->data=0;L->next=NULL;int x;cout<<"请输入链表长度:"; cin>>x;for (int i=0;i<x;i++){int tmp;cin>>tmp;LinkedList t = (LinkedList)malloc(sizeof(LNode));t->data=tmp;t->next=L->next;L->next=t;}}void creatLinkList2(LinkedList &L){L=(LinkedList)malloc(sizeof(LNode));L->data=0;L->next=NULL;LinkedList r=L;int n; cout<<"请输入:";cin>>n;for (int i=0;i<n;i++){int tmp;cin>>tmp;LinkedList q = (LinkedList)malloc(sizeof(LNode));q->data=tmp;q->next=NULL;r->next=q;r=q;}}void printLinkedList(LinkedList L){LinkedList p = L->next;while (p){cout<<p->data<<" ";p=p->next;}cout<<endl;}void reverseLinkedList(LinkedList &L){LinkedList p,q;p=L->next;L->next=NULL;while (p){q=p;p=p->next;q->next=L->next;L->next=q;}}int main(){LinkedList L;creatLinkList2(L);printLinkedList(L);reverseLinkedList(L);printLinkedList(L);return 0;}
二叉树
#include <iostream>using namespace std;#define MAX(a,b) (a>b)?a:b struct BiNode{char data;BiNode* lchild;BiNode* rchild;};typedef BiNode* BiTree;int heightBiTree(BiTree T){if(T == NULL) return 0;else{return MAX(heightBiTree(T->lchild),heightBiTree(T->rchild))+1;}}int countBiTree(BiTree T){if(T == NULL) {return 0;}else{return countBiTree(T->lchild)+countBiTree(T->rchild)+1;}}void preOrder(BiTree T){if(T==NULL) return;cout<<T->data<<" ";preOrder(T->lchild);preOrder(T->rchild);}void inOrder(BiTree T){if(T==NULL) return;inOrder(T->lchild);cout<<T->data<<" ";inOrder(T->rchild);}void lastOrder(BiTree T){if(T==NULL) return;lastOrder(T->lchild);lastOrder(T->rchild);cout<<T->data<<" ";}int main(int argc, char *argv[]){return 0;}
- 数据结构实现
- 数据结构实现
- 堆栈数据结构的实现~
- 数据结构-单链表的实现
- [数据结构]KMP算法实现
- java 实现栈数据结构
- C++实现常见数据结构
- 数据结构---单链表实现(源码)
- 数据结构---栈实现(源码)
- 数据结构实现三元组
- 数据结构实现单链表
- 数据结构实现循环双链表
- matlab实现位图数据结构
- 数据结构实现过程
- C++ 数据结构 树 实现
- 数据结构 队列的实现
- ActionScript实现TreeView数据结构
- 用链表实现堆栈数据结构
- JUnit4 详解
- Python起步之print & input用法总结
- 静态代理模式
- 抽象类 Abstract Class
- VS2010代码在Word 文档中插入并高亮显示
- 数据结构实现
- position的4种属性
- http://www.oralpractice.com/
- Java文件操作I
- httppost方式访问网络数据
- tomcat javaweb(实验四 Servlet开发与MVC设计模式)
- java DAO类 select方法范例,查询关键词
- Linux时间函数
- [Linux]链接_静态库和动态库