#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编译不过
需要设计一个通用的可变参,初始化链表;
原文地址:http://wzsts.blog.51cto.com/10251779/1845138