首页 > 代码库 > 链表的可变参数构造与图的临接表实现 广度有限遍历
链表的可变参数构造与图的临接表实现 广度有限遍历
#include <bits/stdc++.h> using namespace std; typedef struct node { int x; node*next; node(){next=NULL;} }node; typedef struct head { int x; int count; node*head; //head(int xx,int cc,node* P=NULL){x=xx;count=cc;head=p;} }head; void InsertTail(node *head,int val) { if(head == NULL) return ; node *tmp = (node *)malloc(sizeof(node)*1); tmp->next = NULL; tmp->x = val; while(head->next != NULL) { head = head->next; } head->next = tmp; } /* VS2008*/ void List(node *head,...) { if(head == NULL) return ; char* p = (char *)&head+4; int n = *(int *)p; int x = 0; for(int i=0;i < n;++i) { p = p+sizeof(int); x = *(int *)p; InsertTail(head,x); } } void show(node*head) { node *p = head->next; while(p != NULL) { cout<<p->x<<" "; p = p->next; } cout<<endl; } int test() { head H[11]; node *head0 = (node *)malloc(sizeof(node)); node *head1 = (node *)malloc(sizeof(node)); node *head2 = (node *)malloc(sizeof(node)); node *head3 = (node *)malloc(sizeof(node)); node *head4 = (node *)malloc(sizeof(node)); node *head5 = (node *)malloc(sizeof(node)); node *head6 = (node *)malloc(sizeof(node)); node *head7 = (node *)malloc(sizeof(node)); node *head8 = (node *)malloc(sizeof(node)); node *head9 = (node *)malloc(sizeof(node)); node *head10 = (node *)malloc(sizeof(node)); List(head0,1,1); H[0].head=head0; List(head1,2,2,10); H[1].head=head1; List(head3,2,2,4); H[3].head=head3; List(head5,2,4,6); H[5].head=head5; List(head7,2,6,8); H[7].head=head7; List(head9,2,8,10); H[9].head=head9; List(head2,4,2,3,4,10); H[2].head=head2; List(head4,4,2,3,5,6); H[4].head=head4; List(head6,4,4,5,7,8); H[6].head=head6; List(head8,4,6,7,9,10); H[8].head=head8; List(head10,4,1,2,8,9); H[10].head=head10; for(int i=1;i<=10;i++) { H[i].x=i;H[i].count=(i%2)?2:4; } // show(head1);show(head2);show(head3);show(head4);show(head5); // show(head6);show(head7);show(head8);show(head9);show(head10); queue<head>q; vector<int>v; q.push(H[0]); while(!q.empty()) { head h=q.front(); node*p=h.head->next; while(p!=NULL) { if(find(v.begin(),v.end(),p->x)==v.end()) { cout<<p->x<<" "; v.push_back(p->x); q.push(H[p->x]); } p=p->next; } q.pop(); } cout<<endl; return 0; } int main() { test(); cout << "Hello,C++ world of AnycodeX!" << endl; return 0; }
五角星
特别说明
这里的代码 anycodes编译不过
需要设计一个通用的可变参,初始化链表;
链表的可变参数构造与图的临接表实现 广度有限遍历
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。