f[q_,u_]:=u q
q0[x_]:=If[(x>=-1)&&(x≤1),1,0]
F[a_,b_,u_]:=Module[
{dfa,dfb},
dfa=D[f[x,u],x]/.x->a;
dfb=D[f[x,u],x]/.x->b;
If[(dfa>0)&&(dfb>0),Return[f[a,u]],If[(dfa<0)&&(dfb<0),Return[f[b,u]],Return[x/.Solve[f[x,u]==0][[1]]]]]
]
Metoda[Qi0_List,II_,NN_,u_,dt_,dx_]:=
Module[{Qinew,Qin},
Qin=Qi0;
Qinew=Table[0,{i,1,II+1}];
If[NN==0,ListPlot[Qi0,Joined->True],
For[j=0,j<NN,j++,
For[i=2,i<II,i++,
Qinew[[i]]=Qin[[i]]-(dt/dx)(F[Qin[[i]],Qin[[i+1]],u]-F[Qin[[i-1]],Qin[[i]],u]);
];
Qin=Qinew;
];
(*Print[dt<=(dx/(Max[Table[Abs[D[f[Qin[[i]],u]]],{i,1,II+1}]]))];*)
Return[ListPlot[Qinew,Joined->True]]]
]

u=1;
L=2;
II=10;
NN=20;
dx=2 L/II;
dt =dx;
xi=Table[-L+i dx,{i,0,II}];
Qi0=Table[q0[xi[[i]]],{i,1,II+1}];
Metoda[Qi0,II,NN,u,dt,dx]
Animate[Metoda[Qi0,II,t,u,dt,dx],{t,0,NN}]

q01[x_]:=If[(x==0),1,0]
ListPlot[Qi0,Joined->True];
u=1;
L=2;
II=10;
NN=20;
dx=2 L/II;
dt =dx;
xi=Table[-L+i dx,{i,0,II}];
Qi0=Table[q01[xi[[i]]],{i,1,II+1}];
Metoda[Qi0,II,NN,u,dt,dx]
Animate[Metoda[Qi0,II,t,u,dt,dx],{t,0,NN}]

f2[q_,u_]:=u  0.5 q^2
q01[x_]:=If[(x==0),1,0]
Metoda2[Qi0_List,II_,NN_,u_,dt_,dx_]:=
Module[{Qinew,Qin},
Qin=Qi0;
Qinew=Table[0,{i,1,II+1}];
If[NN==0,ListPlot[Qi0,Joined->True],
For[j=0,j<NN,j++,
For[i=2,i<II,i++,
Qinew[[i]]=Qin[[i]]-(dt/dx)(F2[Qin[[i]],Qin[[i+1]],u]-F2[Qin[[i-1]],Qin[[i]],u]);
];
Qin=Qinew;
];
(*Print[dt<=(dx/(Max[Table[Abs[D[f[Qin[[i]],u]]],{i,1,II+1}]]))];*)
Return[ListPlot[Qinew,Joined->True]]]
]
F2[a_,b_,u_]:=Module[
{dfa,dfb},
dfa=D[f2[x,u],x]/.x->a;
dfb=D[f2[x,u],x]/.x->b;
If[(dfa>0)&&(dfb>0),Return[f2[a,u]],If[(dfa<0)&&(dfb<0),Return[f2[b,u]],Return[x/.Solve[f2[x,u]==0][[1]]]]]
]
ListPlot[Qi0,Joined->True];
u=10;
L=2;
II=10;
NN=20;
dx=2 L/II;
dt =dx;
xi=Table[-L+i dx,{i,0,II}];
Qi0=Table[q01[xi[[i]]],{i,1,II+1}];
Metoda[Qi0,II,NN,u,dt,dx]

Animate[Metoda[Qi0,II,t,u,dt,dx],{t,0,NN}]