# Matrix Operation

I have a $3\times3$ matrix A, and a function sTrans that outputs two $3\times3$ matrices in a list when given a $3\times3$ matrix.

So for the input

A = {{1,2,3} , {4,5,6} , {7,8,9}}


the output is:

sTrans[A]

{ {{3, 1, 2}, {4, 5, 6}, {7, 8, 9}} , {{1, 2, 3}, {6, 4, 5}, {7, 8, 9} }}

And now I want to append the two matrices in a queue. The enQueue operation:

enQueue[q_, elem_] := If[FreeQ[q,elem],qt++; q[[qt]]= elem]


How should I write the code without using loops?

(P.S. I've heard multiple times that the whole concept of MMA is against For and While loops)

-

enQueue[q_, elements_] := Join[q, Complement[elements, q]]

If you just want to append elements Join alone will suffice. I'm confused because your code says "if element elem is not in q, then set qt=qt+1. If the element does already exist, set q[[qt]] to element." So it's like you only want duplicates in the queue and gaps in the list (perhaps filled with a default value?). Also you will overwrite the same position in q multiple times if several new elements appear in a sequence. To me this is non-sensical and to get proper help, if that's what you want to do, you need to give more details about the bigger picture.