Bạn ơi có thể giải thích cho mình cái hàm tìm chu trình euler từ 1 điểm cho trước nó hoạt động dựa trên giải thuật nào ko?
Thuât toán chu trình Euler:
Mong mọi người góp ý thêm haC Code:
#include<iostream.h> #include<malloc.h> #include<conio.h> #include<stdio.h> #include<ctype.h> #define max 20 typedef struct Dinh { int data; Dinh *next; }DINH; DINH *G[max]; int n; DINH *topI; int top() { return topI->data; } // CAP PHAT DINH *capPhat() { DINH *p; return p; } // KHOI TAO GIA TRI BAN DAU void khoiTao() { //Khoi tao mang G for (int i=1;i<=n;i++) { G[i]=capPhat(); G[i]->data=i; G[i]->next=NULL; } } // CHEN CAC DINH KE VAO G[Ii] void dSKeDinh(int i) { DINH *p; char t; int temp; do { p=capPhat(); p->data=temp; p->next=G[i]->next; G[i]->next=p; }while (t=='C'); } //NHAP DL void nhapDL() { khoiTao(); for (int i=1;i<=n;i++) dSKeDinh(i); } //IN DS DINH KE RA MAN HINH void inDSKeDinh(int i) { DINH *p; p=G[i]; while(p) { p=p->next; } } //HAM IN DANH SACH G void inDL() { for (int i=1;i<=n;i++) { inDSKeDinh(i); } } void taoStack() { topI=NULL; } int stackRong() { return (topI==NULL); } int pop()//Lay nhan cua dinh <= stack { DINH *p; int temp; if(stackRong()) return 0; p=topI; temp=p->data; topI=p->next; return temp; } void push(int i) { DINH *p; p=capPhat(); p->data=i; p->next=topI; topI=p; } int Bac[max],CE[max]; //TINH TONG SO BAC void tinhBac() { int i; DINH *p; for(i=1;i<=n;i++) { Bac[i]=0; p=G[i]->next; while(p) { ++Bac[i]; p=p->next; } } } //KIEM TRA G LA EULER int laEuler() { int i=1,stop=0; while(i<=n && !stop) { if(Bac[i]<2 || Bac[i]%2==1) stop=1; ++i; } if(stop) return 0;//Khong la Euler return 1; } //TIM CHU TRINH EULER void Euler(int i) { DINH *p,*q; int x,y; taoStack(); int dem=0; push(i); while(!stackRong()) { x=top(); p=G[x]->next; if(p) { y=p->data; push(y); //Loai y khoi Ke(x) G[x]->next=p->next; //Loai x khoi Ke(y) q=G[y]; p=G[y]->next; while(p->data!=x) { q=p; p=p->next; } // if(q==G[y]) // { // G[y]->next=p->next; // free(p); // } // else // { q->next=p->next; // } } else { x=pop(); CE[++dem]=x; } } for (int j=1;j<=dem;j++) } int main() { int i; // clrscr(); nhapDL(); inDL(); tinhBac(); if(laEuler()) { Euler(i); } else { } getch(); return 0; }
Không biết ghi gì luôn ...
Bạn ơi có thể giải thích cho mình cái hàm tìm chu trình euler từ 1 điểm cho trước nó hoạt động dựa trên giải thuật nào ko?
ttecak ?
Không biết ghi gì luôn ...