Page 49 - Touchcode_C7_Flipbook
P. 49

Dictionary: It stores words in an alphabetical order.
                  In Sorting, we take a jumbled set of objects and arrange them in order (ascending or

                  descending).  To sort items, you need to compare two items.

                  Sorting is useful because:
                      It helps you to view the object ‘which is the tallest/smallest/fastest item in the given
                      list.
                      It arranges things in order that can make other algorithms work better.

                  Consider an example:

                  Suppose you have a lot of books, and all the books are mixed up. You can arrange the books:
                      from tallest height to smallest

                      in an  alphabetical order
                      by the frequency in which you use them

                  Flowchart:
                                        Start


                            Pick up a book from the bundle




                                     Is this book                   Place it after
                                   smaller than the       No      smaller books in
                                  other books in the             the sorted bundle
                                       bundle?

                                           Yes


                          Place it before other books           Are there any more       No            Stop
                             in the sorted bundle                 books left in the
                                                                 unsorted bundle?

                                                                           Yes


                  Pseudocode:
                  Program Start

                      Pick the book from the bundle
                    Check Book size

                    IF (book is smaller than the other in the sorted bundle)
                    THEN
                    Place it before other books in the sorted bundle

                    ELSE

                                                                                           Fun with Functions    47
   44   45   46   47   48   49   50   51   52   53   54