Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class node
- {
- public:
- int value;
- node *next = NULL;
- }
- class image
- {
- public:
- image()
- {
- for(int i = 0; i < size; i++)
- {
- gragh[i] = new node;
- }
- }
- node *gragh[size];
- void create();
- void list();
- }
- void image::create()
- {
- for(int i = 0; i < size; i++)
- {
- for(int j = 0; j < size; j++)
- {
- node* x=new node();
- x->value = j;
- if(fig[i][j] == 1)
- {
- node* p = gragh[i];
- while(p->next != NULL)
- {
- p = p->next;
- }
- p->next = x;
- }
- }
- }
- }
- void image::list()
- {
- for(int i = 0; i < size; i++)
- {
- cout<<"頂點:"<<i+1<<"=>";
- node* p = gragh[i]->next;
- while(p != NULL)
- {
- cout<<"["<< p->value+1 <<"]\t";
- p = p->next;
- }
- cout<<endl;
- }
- }
- void visit(int i, int *isvisit, node** head)
- {
- node* ptr;
- isvisit[i] = 1;
- cout<< "visit=" << i+1 <<endl;
- ptr = head[i]->next;
- while(ptr != NULL)
- {
- if(isvisit[ptr->value] == 0)
- visit(ptr->value, isvisit, head);
- ptr = ptr->next;
- }
- }
- void main()
- {
- image pl;
- int isvisit[size];
- for(int i = 0; i < size; i++)
- {
- isvisit[i] = 0;
- }
- pl.create();
- pl.list();
- visit(0, isvisit, pl.gragh);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement