from here on, the program is independent of the implementations of the data abstractions

topsort(pn,topologicalsort)

/* Inputs the number of objects n and the

partial order and generates a solution in

topologicalsort.

*/

int *pn;

outputarray topologicalsort;

{

countcollection count;

succ_collection succ;

bagcollection bag;

int i,j,obj;

printf("\n enter n between 1 and %d\n",LIMIT-1);

scanf("%d",pn);

predinitialization(*pn,count);

succinitialization(*pn,succ);

while (nextpair(&i,&j))

{

increase(j,count);

insert(i,j,succ);

{

baginitialization(&bag,*pn,count);

while(!emptybag(bag))

{

remove(&bag,&obj);

update(succ,obj,&bag,count);

}

copy(*pn,topologicalsort,ranking);

}

nextpair(pi,pj)

int*pi,*pj;

/* Input the next pair and return true

only if it was not the sentinel pair.

*/

{

print("\n enter a pair \n");

scanf("%d %d",pi,pj);

return(!((*pi == 0) && (*pj == 0)));

}

update(succ,obj,pbag,count)

/* Update the counts of all successors of obj

and place any whose counts become zero

into bag.

*/

succ_collection succ;

int obj;

bagcollection *pbag;

countcollection count;

{

listpointer listname,recordpointer,access_succ();

listname = access_succ(obj,succ);

recordpointer = listname;

while(anotherrecord(recordpointer))

{

process(listname,recordpointer,pbag,count);

recordpointer = next(recordpointer);

}

}