Advertisement
AntonioLinux

Untitled

Jan 11th, 2014
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.10 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <windows.h>
  4.  
  5. struct vertex {
  6. int id;
  7. struct vertex *next;
  8. };
  9. typedef struct vertex* verticepunt; //
  10.  
  11. /*Structure for dfs */
  12. struct visitaVertice {
  13. int color; //
  14. int p; //
  15. int d; //
  16. int f; // time to vertex
  17. };
  18.  
  19. //new vertex
  20. verticepunt newVertex(){
  21. verticepunt v;
  22. v=(verticepunt)malloc(sizeof(struct vertex));
  23. v->next=NULL;
  24. return v;
  25. }
  26. /*INIT*/
  27. void init(verticepunt list[],int n){
  28. int i;
  29. for(i=0;i<n;i++)
  30. list[i]=NULL;
  31.  
  32. }
  33.  
  34. /*INIT DFS*/
  35. void initdfs(struct visitaVertice dfsData[],int n){
  36. int i;
  37. for(i=0;i<n;i++){
  38. dfsData[i].color=0;
  39. dfsData[i].p=-1;
  40. dfsData[i].d=0;
  41. dfsData[i].f=0;
  42. }
  43. }
  44.  
  45. /*ADD EDGE*/
  46. void AdjList(verticepunt list[],int n){
  47. int k,i,j;
  48. // int temp; caloclo del tempo computazionale
  49. verticepunt nuovo,p;
  50. for(i=1;i<n;i++){
  51. for(j=0;j<i;j++){
  52. k= randomGen(n);
  53. if(k==1){
  54. nuovo=newpunt();
  55. nuovo->id=i;
  56. p=list[j];
  57. if(p==NULL){
  58. list[j]=nuovo;
  59. // temp=temp+1;
  60. } else { //caso in cui sia diverso da 1
  61. while(p->next!=NULL)
  62. p->next=nuovo;
  63.  
  64. }
  65. }
  66. }
  67. }
  68. //return (temp)
  69. }
  70.  
  71.  
  72.  
  73. //Random genenrator
  74. int randomGen(int end){
  75. int fine;
  76. fine= end -1;
  77. srand((unsigned)time(0));
  78. int generated = rand() % fine + 1;
  79. return generated;
  80. }
  81.  
  82.  
  83. /**DFS*/
  84. void dfs(verticepunt list[],int n){
  85. int i;
  86. verticepunt p;
  87. struct visitaVertice dfsdata[n]; //Struttura dati che contiene i dati dfs
  88. initdfs(dfsdata,n); //Inizializza tale lista
  89. tempo=0;
  90. for(i=0;i<n;i++){ //Per ogni v appartenente a G.V
  91. if(dfsdata[i].color==0) //Colore bianco
  92. dfs_visit(list,dfsdata,i);
  93.  
  94. }
  95.  
  96. }
  97. /*DFS VISIT*/
  98. void dfs_visit(verticepunt list[],struct visitaVertice dfsdata[],int i){
  99. verticepunt p,punt,nuovo;
  100. int k;
  101.  
  102. tempo=tempo +1;
  103. dfsdata[i].color=1; //Colore grigio
  104. dfsdata[i].d=tempo;
  105.  
  106. p=list[i];
  107. while(p!=NULL){
  108. k=p->id;
  109. if(dfsdata[k].color==0){
  110. dfsdata[k].p=i;
  111.  
  112. }
  113. p=p->next;
  114. }
  115. dfsdata[i].color=2; //Colore nero
  116. tempo=tempo+1;
  117. dfsdata[i].f=tempo;
  118.  
  119. }
  120.  
  121. /*transposed OF Graph*/
  122. verticepunt getTrasposta(verticepunt list[],int n)
  123. {
  124. verticepunt trasposta[n];
  125. verticepunt e;
  126. verticepunt pT;
  127. /*faccio scorrere array dei vertici*/
  128. int j;
  129. for(j=0;j<n;j++){
  130. e=list[j];
  131. pT=inversion(e);
  132. trasposta[j]=pT;
  133. }
  134. return trasposta;
  135. }
  136.  
  137. /*now i have a error !!!!!!*/
  138. void inversion(verticepunt p) {
  139. verticepunt q, q1=NULL;
  140. int i=0;
  141. while (p != NULL) {
  142. q =(verticepunt)malloc(sizeof(struct vertex));
  143. q->id = p->id;
  144. q1 = q;
  145. p = p->next;
  146. }
  147. return(q1);
  148. }
  149.  
  150. int main(int argc, char** argv) {
  151.  
  152. return (EXIT_SUCCESS);
  153. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement