《数据结构》实验报告
学号:
姓名:
班级:
}
cout< using namespace std; struct node{ int data ; node* next; }; class list{ public: list(); void create_R(); void print(); node *locate(const int x)const; private: int count ; node *head; }; list::list(){ head=new node; head->next=NULL; count=0; } void list::create_R(){ int x; cin>>x; node *rear=head; while(x!=-1) { count++; node *s=new node; s->data=x; rear->next=s; rear=s; rear->next=NULL; cin>>x; } } void list::print(){ node *p; p=head->next; while(p!=NULL) { cout< list::list(){ head=new node; head->next=NULL; count=0; } void list::create_R(){ int x; cin>>x; node *rear=head; while(x!=-1) { count++; node *s=new node; s->data=x; rear->next=s; rear=s; rear->next=NULL; cin>>x; } } void list::insert(const int i,const int x){ node *p=NULL; p=head->next; int j=1; while(p!=NULL&&j<(i-1)){ p=p->next; j++;} node *s=new node; s->data=x; s->next=p->next; p->next=s; count++; } void list::print(){ node *p; p=head->next; while(p!=NULL) { cout< } } void list::delete_element(const int i){ }; class list{ public: node *p=NULL,*u=NULL; int j; p=head;j=0; while (j!=(i-1)&&p!=NULL){ p=p->next; j++; } if(i<1||i>count) cout<<\"删除位置错误\"< void list::print(){ node *p; p=head->next; while(p!=NULL) { cout< cout< A.create_R(); A.print(); cout< list::list(){ head=new node; head->next=NULL; count=0; } void list::create_R(){ int x; cin>>x; node *rear=head; while(x!=-1) { count++; node *s=new node; s->data=x; rear->next=s; rear=s; rear->next=NULL; cin>>x; } } void list::insert(const int x){ node *p,*s; p=head; while((p->next!=NULL)&&p->next ->data //if(p->next ==NULL||p->next ->data>x) s=new node; s->data=x; s->next=p->next; p->next=s; count++; } void list::print(){ node *p; p=head->next; while(p!=NULL) { cout< cout< A.create_R(); A.insert(55); cout< class list{ public: list(); void create_R(); void print(); node*get_head(){return head;}; void copy1(list A,list B); void copy2(list A,list C); private: int count ; node *head; }; list::list(){ head=new node; head->next=NULL; count=0; } void list::create_R(){ int x; cin>>x; node *rear=head; while(x!=-1) { count++; node *s=new node; s->data=x; rear->next=s; rear=s; rear->next=NULL; cin>>x; } } void list::copy1(list A,list B){ node *s,*PA,*PB; PA=A.get_head()->next; PB=B.get_head(); while(PA!=NULL){ s=new node; s->data=PA->data; PB->next=s; PB=s; count++; PB->next=NULL; if(PA->next==NULL) break; PA=PA->next->next; } } void list::copy2(list A,list C){ node* s,*PA,*PC; PA=A.get_head()->next->next; PC=C.get_head(); while(PA!=NULL){ s=new node; s->data=PA->data; PC->next=s; PC=s; count++; PC->next=NULL; if((PA->next)==NULL) break; PA=PA->next->next; } } void list::print(){ node *p; p=head->next; while(p!=NULL) { cout< cout< class list{ public: list(); void create_R(); void print(); node *get_head(){return head;}; void merge_list(list A,list B,list C); private: int count ; node *head; }; list::list(){ head=new node; head->next=NULL; count=0; } void list::create_R(){ int x; cin>>x; node *rear=head; while(x!=-1) { count++; node *s=new node; s->data=x; rear->next=s; rear=s; rear->next=NULL; cin>>x; } } void list::merge_list(list A,list B,list C) { node *pa,*pb,*rc,*u; rc=C.get_head(); pa=A.get_head()->next; pb=B.get_head()->next; while(pa!=NULL&&pb!=NULL) { if(pa->data pa=pa->next;pb=pb->next; } } } void list::print(){ node *p; p=head->next; while(p!=NULL) { cout< cout< cout<<\"input A:\"< 1. #include typedef struct bnode {char data; struct bnode *lchild,*rchild; }; typedef bnode *bitre; void create_pre_bitre_(bitre { char ch; cin>>ch; if(ch=='.') T=NULL; else{ T=new bnode; T->data =ch; create_pre_bitre_(T->lchild ); create_pre_bitre_(T->rchild ); } } int high(bnode *T) { if(T==NULL) return 0; else return ((high(T->lchild )>high(T->rchild ))?high(T->lchild ):high(T->rchild ))+1; } int main() { bitre t; cout<<\"输入该二叉树的先序序列\"< struct bnode *lchild,*rchild; }; typedef bnode *bitre; int n=0; void create_pre_bitre_(bitre &T) { char ch; cin>>ch; if(ch=='.') T=NULL; else{ T=new bnode; &T) T->data =ch; create_pre_bitre_(T->lchild ); create_pre_bitre_(T->rchild ); } } void inorder(bnode *T) { if(T!=NULL) { n++; inorder(T->lchild ); cout< int main() { bitre t; cout<<\"输入该二叉树的先序序列\"< struct bnode *lchild,*rchild; }; typedef bnode *bitre; void create(bitre &T,int i) { if(i>max) T=NULL; else{ if(A[i]=='.') T=NULL; else{ T=new bnode; T->data=A[i]; create(T->lchild ,2*i); create(T->rchild ,2*i+1);} } } void create_A() { cout<<\"请输入数组:\"< void preorder(bnode *T) { if(T!=NULL) {cout< void inorder(bnode *T){ if(T!=NULL) { inorder(T->lchild); cout< void postorder(bnode *T) { if(T!=NULL) { postorder(T->lchild); postorder(T->rchild); cout< int main() { bitre t; create_A(); create(t,i); cout<<\"该二叉树的先序序列为\"; preorder(t); cout< { char ch; cin>>ch; if(ch=='.') T=NULL; else{ T=new bnode; T->data =ch; create_pre_bitre_(T->lchild ); create_pre_bitre_(T->rchild ); } } void exchange_child(bitre &T) { bitre temp; if(T!=NULL) { temp=T->lchild ; T->lchild =T->rchild ; T->rchild =temp; exchange_child(T->lchild); exchange_child(T->rchild); } } void preorder(bnode *T) { if(T!=NULL) {cout< void inorder(bnode *T) { if(T!=NULL) { inorder(T->lchild ); cout< void postorder(bnode *T) { if(T!=NULL) { postorder(T->lchild ); postorder(T->rchild ); cout< } } int main() { bitre t; cout<<\"输入该二叉树的先序序列\"< struct bnode *lchild,*rchild; }; typedef bnode *bitre; void create_pre_bitre_(bitre &T) { char ch; cin>>ch; if(ch=='.') T=NULL; else{ T=new bnode; T->data =ch; create_pre_bitre_(T->lchild ); create_pre_bitre_(T->rchild ); } } void preorder(bnode *T) { if(T!=NULL) {cout< void inorder(bnode *T) { if(T!=NULL) { inorder(T->lchild ); cout< void postorder(bnode *T) { if(T!=NULL) { postorder(T->lchild ); postorder(T->rchild ); cout< int main() { bitre t; cout<<\"输入该二叉树的先序序列\"< #include cout<<\"请输入数据长度\"<
因篇幅问题不能全部显示,请点此查看更多更全内容
Copyright © 2019- 7swz.com 版权所有 赣ICP备2024042798号-8
违法及侵权请联系:TEL:199 18 7713 E-MAIL:2724546146@qq.com
本站由北京市万商天勤律师事务所王兴未律师提供法律服务