Hello,

I have to make a leader election emulator on a tree. The whole project is based on this pseudocode:

Have anyone did something similar or can publish a similar C source code for leader election on trees?Code:var ws: boolean init false; wr: integer init 0; rec[q]: Boolean for each q ∈ Neigh init false; v: P init p; state: (sleep, leader, lost) init sleep; begin if p is initiator then begin ws:=true; forall q ∈ Neigh do send <wakeup> to q end; while wr < #Neigh do begin receive <wakeup>; wr:=wr+1; if not ws then begin ws:=true; forall q ∈ Neigh do send <wakeup> to q end end; /* Now start the tree algorithm */ while #{q: ¬rec[q]} >1 do begin receive <tok,r> from q; rec[q]:=true; v:=min(v,r) end; send <tok, v> to q0 with ¬rec[q0]; receive <tok,r> from q0; v:=min(v,r); if v=p then state:=leader else state:=lost; forall q ∈ Neigh, q≠q0 do send <tok,v> to q end

I am totally lost... Don't know how to start except define variables....

Thanks a lot.