《将链表分为a,b两个奇偶链表代码》由会员分享,可在线阅读,更多相关《将链表分为a,b两个奇偶链表代码(3页珍藏版)》请在金锄头文库上搜索。
1、#include enum error_codesuccess,arrange_error; typedef struct node int data; struct node*next; node; class list public: list();void creat_R();int length()const; node*get_head() return head; void display(); private: int count; node*head; ; list:list () head=new node; head-next =NULL; count=0; int lis
2、t:length ()const return count; void list:creat_R () int x; cinx; node*rear=head; while(x!=-1) count+; node*s=new node; s-data =x; s-next =NULL; rear-next =s; rear=s; cinx; void list:display ()node*p=head-next ; while(p!=NULL) coutdata next ; void divide(list node*pb=b.get_head (); node*u,*v; while(p
3、a-next !=NULL) if(pa-next-data %2=0) v=new node; u=pa-next ; v-data =u -data ; v-next =NULL; pb-next =v; pb=v; pa-next =u-next ; delete u; else pa=pa-next ; void main() list a,b; cout“请输入 A 链表:“; a.creat_R (); cout“输出 A 链表:“; a.display (); coutendl; divide (a,b); cout“输出操作后的 A 链表:“; a.display (); coutendl; cout“输出 B 链表:“; b.display ();