Give students names or initials:
A=Alice, B=Bob, C=Cathy, D=David
Suppose Alice and David do not want to stand next to each other, then you have the following arrangements: 4! / 2! = 12. A,D cannot stand next to each other
{A, B, C, D} | {A, B, D, C} | {A, C, B, D} | {A, C, D, B} {B, A, C, D} | {B, D, C, A} | {C, A, B, D} | {C, D, B, A} {D, B, A, C} | {D, B, C, A} | {D, C, A, B} | {D, C, B, A}