Now that the new 12CP has 81 cash flow registers with accompanying

Nj's (that can have values from 0 to 99) I thought that I find some

non-obvious use for them. Also, I've been thinking about the median

problem that Gene presented a while back. Combining these ideas along

with other people's ideas about incremental sorting I came up with a

little linked list insertion sort program.

This program treats the CFj/Nj registers as a linked list and does an

incremental insertion sort into it. It works on the original HP 12C

and the later model HP 12C Platinum (and related editions), but will

not work as-is on the early model Platinum due the limitation on N(0).To use the program:

(1) Set n<--0, N(0)<--0 (0, STO n, Nj)

(2) Enter each number to sort and press R/S. The program will execute

CFj adding the data to the cash flow registers and then "link" this

number into the sorted data structure. Data will remain in the order

that you enter them, only the Nj's are modified. (Entry will take a

varying amount of time based on how many numbers have been previously

entered and where the current number is in sorted order.)N(0) contains the number of the CF register with the lowest data

value. The N(x) register contains the number of the CF register with

the next lowest value, etc.. The CF register with the highest data

value will have a value of zero in N(x) indicating the end of the

list. Note that CF(0) does not contain a data element.Keystrokes |Display | Comments

[f][P/R] | |

[f]CLEAR[PRGM] |00- |

[g][CFj] |01- 43 14 | increment n and add to CF register

[STO]0 |02- 44 0 | save the data being added for easy access

[RCL][n] |03- 45 11 |

[STO][i] |04- 44 12 | save n

0 |05- 0 |

[STO][PV] |06- 44 13 | PV is the current value of the link

[STO][n] |07- 44 11 | use it to point to the next CF register

[RCL][g][Nj] |08- 45,43 15 |

[STO][FV] |09- 44 15 | save the next value of the link

[STO][n] |10- 44 11 |

[RCL][g][CFj] |11- 45,43 14 |

[RCL]0 |12- 45 0 |

[g][x<=y] |13- 43 34 | compare CFj with the new entry

[g][GTO]17 |14- 43,33 17 | same or smaller value so insert it into the linked-list here

[RCL][FV] |15- 45 15 |

[g][GTO]06 |16- 43,33 06 | follow the link if the new entry is larger

[RCL][PV] |17- 45 13 |

[STO][n] |18- 44 11 |

[RCL][i] |19- 45 12 |

[g][Nj] |20- 43 15 | current link now points to latest data entry

[STO][n] |21- 44 11 | restore n

[RCL][FV] |22- 45 15 |

[g][Nj] |23- 43 15 | link of last data entry now points to

[g][GTO]00 |24- 43,33 00 | where previous link pointed

[f][P/R] | |The following program can be used to traverse the linked list displaying the data in sorted order:

Keystrokes |Display | Comments

[f][P/R] | |

[f]CLEAR[PRGM] |00- |

0 |01- 0 |

[STO][n] |02- 44 11 |

[RCL][g][Nj] |03- 45,43 15 |

[STO][PV] |04- 44 13 |

[STO][n] |05- 44 11 |

[RCL][g][CFj] |06- 45,43 14 |

[g][PSE] |07- 43 31 |

[RCL][PV] |08- 45 13 |

[g][x=0] |09- 43 35 |

[g][GTO]00 |10- 43,33 00 |

[g][GTO]02 |11- 43,33 02 |

[f][P/R] | |This next program will find the N'th largest data element in the sorted list; call with N in the X register:

Keystrokes |Display | Comments

[f][P/R] | |

[f]CLEAR[PRGM] |00- |

[STO]0 |01- 44 0 |

0 |02- 0 |

[STO][n] |03- 44 11 |

[RCL]0 |04- 45 0 |

[g][x=0] |05- 43 35 |

[g][GTO]11 |06- 43,33 11 |

1 |07- 1 |

[STO][-]0 |08- 44 30 0 |

[RCL][g][Nj] |09- 45,43 15 |

[g][GTO]03 |10- 43,33 03 |

[RCL][g][CFj] |11- 45,43 14 |

[g][GTO]00 |12- 43,33 00 |

[f][P/R] | |

[Thanks to tony(nz) for the nifty 12C formatting utility!]

*Edited: 17 June 2006, 5:21 a.m. *