Texas Instruments TI89 Developer Guide - Page 741
push_median, Example, push_reversed_tail
![]() |
UPC - 033317198566
View all Texas Instruments TI89 manuals
Add to My Manuals
Save this manual to your list of manuals |
Page 741 highlights
Appendix A: System Routines - Lists and Matrices 699 push_median (continued) Example: This example pushes a list on the estack that corresponds to the median for the input list. For each element in the input list the element in the output list is a negative one if the element is less than the median, a zero if it is equal to the median, and a positive one if it greater than the median. Note that since the output list is created in reverse order on the estack, push_reversed_tail is used to reverse the order of the list back to normal. const BYTE INT_NEG1[] = {END_TAG,1,1,NEGATIVE_INTEGER_TAG}; const BYTE INT_0[] = {END_TAG,0,NONNEGATIVE_INTEGER_TAG}; const BYTE INT_1[] = {END_TAG,1,1,NONNEGATIVE_INTEGER_TAG}; EStackIndex old_top, idx, median_idx, cond_idx; old_top = top_estack; push_quantum(END_TAG); push_Float(-5.0); push_Float(1.0); push_Float(2.0); push_Float(4.0); push_Float(99.0); idx = top_estack; push_quantum(LIST_TAG); push_median( idx+1 ); median_idx = top_estack; push_quantum( END_TAG ); while (END_TAG != ESTACK(idx)) { push_difference( median_idx, idx ); if (is0(top_estack)) cond_idx = (EStackIndex) INT_0+2; else if (is_positive(top_estack)) cond_idx = (EStackIndex) INT_1+3; else cond_idx = (EStackIndex) INT_NEG1+3; delete_expression( top_estack ); push_expression( cond_idx ); idx = next_expression_index( idx ); } idx = top_estack; push_reversed_tail( idx ); delete_between ( old_top, idx ); push_quantum( LIST_TAG ); TI-89 / TI-92 Plus Developer Guide Not for Distribution Beta Version January 26, 2001
![](/manual_guide/products/texas-instruments-ti89-developer-guide-95b636f/741.png)