How to avoid that listings are interrupted by floats?

You can adjust the placing of floats the following ways:

For once you could add \FloatBarrier from the placeins package before the listing to flush all previous floats. This wont help if the table is defined just after it.

The \suppressfloats macro allows you to suppress floats on the current page. You could add it before the listing inside an \afterpage{...} (afterpage package) so that it counts for the second page of the listing.

There is also the flafter package which makes floats only appear after their definition. This should handle a table defined shortly after the listing.


Another (and less hacky) possibility is, to add the float Parameter to your listing. It will then float like the tables do, but floating environments don't interrupt each other:

\begin{lstlisting}[float]
Some Code
\end{lstlisting}

I consider this to be less hacky, because normally having floating content interrupt non floating content ist what you expect and trying to prevent it is contrary to the concepts of TeX.