Linearne

L=1;
u=1;
f[q_]:=u*q;
Df[q_]:=D[f[qq],qq]/.qq->q;
q0[x_]:=Which[
x<-0.5,0,
-0.5<=x<=0.5,1,
x>0.5,0
];
II=40;
NN=10;
dx=2L/II;
xx=Table[-L+i*dx,{i,0,II}];

F[a_,b_]:=Which[
(Df[a]>0)&&(Df[b]>0),f[a],
(Df[a]<0)&&(Df[b]<0),f[b],
True,0
]

dt=dx/2;

Q0=Table[q0[xx[[i]]],{i,1,Length[xx]}];
Q={};
AppendTo[Q,Q0];

For[n=1,n≤NN,n++,
pom=Table[Q[[n,i]]-dt/dx*(F[Q[[n,i]],Q[[n,i+1]]]-F[Q[[n,i-1]],Q[[n,i]]]),{i,2,Length[Q[[n]]]-1}];
PrependTo[pom,0];
AppendTo[pom,0];
Print[pom];
AppendTo[Q,pom];
]

ListLinePlot[Q[[n]]]

Burgers-nedokoncene

L=1;
u=1;
f[q_]:=u*0.5*q^2;
Df[q_]:=D[f[qq],qq]/.qq->q;
q0[x_]:=Which[
x<=-0.5,0,
-0.5<x<=0,2*x+1,
0<x<=0.5,-2*x+1,
x>0.5,0
];
II=40;
NN=10;
dx=2L/II;
xx=Table[-L+i*dx,{i,0,II}];

Plot[q0[x],{x,-L,L}]

sol=Solve[Df[q]==0]
qs=q/.sol[[1]]

F[a_,b_]:=Which[
(Df[a]>0)&&(Df[b]>0),f[a],
(Df[a]<0)&&(Df[b]<0),f[b],
True,f[qs]
]

dt=dx/(Max[Table[Abs[Df[Q0[[i]]]],{i,1,Length[Q0]}]])

Q0=Table[q0[xx[[i]]],{i,1,Length[xx]}];
Q={};
AppendTo[Q,Q0];

For[n=1,n≤NN,n++,
pom=Table[Q[[n,i]]-dt/dx*(F[Q[[n,i]],Q[[n,i+1]]]-F[Q[[n,i-1]],Q[[n,i]]]),{i,2,Length[Q[[n]]]-1}];
PrependTo[pom,0];
AppendTo[pom,0];
Print[pom];
AppendTo[Q,pom];
]

ListLinePlot[Q[[10]]]