Assume a sequentially allocated list occupies memory locations F(first item) through M (maximum location). Further assume the last item in the list currently occupies location L (current last item) and there is at least one free place in the list (L < M).
Insert a new item in lexicographic (ascending sorted order, no check for overflow; written for clarity; if L = M then overflow):
1) Prompt the user for the value to insert y.
2) K := L;
While ( K >= F and List[ K] > y) loop
List[ K+1] <-- List[K];
K <-- K – 1;
End loop;
If (K = L) // New last item in list
List[ L+1 ] <-- y
Else If ( K < F) // New first item in list
List[ F ] <-- y;
Else // New interior item in list
List[ K + 1 ] <-- y;
End if;
L <-- L + 1;
How do I write the pseudo to delete from the list? Would I just pretty much reverse everything?
New contributor
AMB007 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.