I have been woking on a routine that removes an element from anywhere in a list and appending it to the end of the list.
Input: Ans=number to move to the end of the list
Output: Ans=list with moved element
Destroyed: three real variables and modifies the list
This code prevents the addition of elements that are not already in the list.
Code:
Are there any optimizations? Is there a better way to do this? Could SortA() be used instead?
If this is the most efficient method, then I may post this in the Code Fragments and Routines topic.
Input: Ans=number to move to the end of the list
Output: Ans=list with moved element
Destroyed: three real variables and modifies the list
This code prevents the addition of elements that are not already in the list.
Code:
Ans->A
dim(ʟQ->Q
max(seq(X(A=ʟQ(X)),X,1,Q→B
If Ans=1:DeltaList(cumSum(ʟQ→ʟQ
If B≥2 and B≤Q-1:augment(seq(ʟQ(X),X,1,Ans-1),seq(ʟQ(X),X,Ans+1,Q→ʟQ
If B≠0:Q-1→dim(ʟQ
ʟQ
If B≠0:augment(Ans,{A→ʟQ
Are there any optimizations? Is there a better way to do this? Could SortA() be used instead?
If this is the most efficient method, then I may post this in the Code Fragments and Routines topic.