Ask Question

Name:
Title:
Your Question:

Answer Question

Name:
Your Answer:
User Submitted Source Code!


Description:
  exe file
Language: C/C++
Code:
#include <stdio.h>
#include <stdlib.h>
#define MAX_VERTICES 30

typedef struct node nodePointer;
typedef struct node{
    int vertex;
    int duration;
    nodePointer *link;
}nodePointer;

nodePointer *e1,*e2,*e3,*e4,*e5,*e6,*e7,*e8,*e9,*e10,*e11;
e1->vertex=0;
e1->duration=6;
e2->vertex=0;
e2->duration=4;
e3->vertex=0;
e3->duration=5;
e4->vertex=1;
e4->duration=1;
e4->link=e5;
e5->vertex=0;
e5->duration=1;
e6->vertex=3;
e6->duration=2;
e7->vertex=4;
e7->duration=9;
e8->vertex=4;
e8->duration=8;
e8->link=e9;
e9->vertex=5;
e9->duration=4;
e10->vertex=6;
e10->duration=2;
e10->link=e11;
e11->vertex=7;
e11->duration=4;


typedef struct hdnodes{
    int count; 
    nodePointer *link;
} hdnode;
hdnode *graph[MAX_VERTICES];

graph[0]->count=3;
graph[1]->count=1;
graph[1]->link=e1;
graph[2]->count=1;
graph[2]->link=e2;
graph[3]->count=1;
graph[3]->link=e3;
graph[4]->count=2;
graph[4]->link=e4;
graph[5]->count=1;
graph[5]->link=e6;
graph[6]->count=1;
graph[6]->link=e7;
graph[7]->count=1;
graph[7]->link=e8;
graph[8]->count=0;
graph[8]->link=e10;

void topsort (hdnode *graph[], int n){
    int i,j,k,top;
    nodePointer *ptr;
    top = -1;
    for (i=0;i<n;i++)
        if(!graph[i]->count){
            graph[i]->count=top;
            top = i;
        }
    for (i=0;i<n;i++)
        if (top == -1){
            printf("n network has a cycle. sort terminated. n"); exit(1);
        }
        else{
            j=top; 
            top = graph[top]->count;
            printf("%d, ",j); 
            for (ptr=graph[j]->link; ptr; ptr=ptr->link){
                k = ptr->vertex; 
                if(lastest[k] > latest[j] - ptr->duration)
                    latest[k] = latest[j] - ptr->duration;
                graph[k]->count --; 
                if (!graph[k]->count){ 
                    graph[k]->count = top; 
                    top = k; 
                }
            }
        }

    int main(){
        topsort(&graph[0],9);

        return 0;
    }
}
          
Comments: