Posts

Showing posts with the label Inserting a Card in a List of Sorted Cards

Inserting a Card in a List of Sorted Cards in Python

Image
                                                Inserting a Card  in a List of Sorted Cards Problem Statement       Imagine that you are playing a card game.  You are holding the cards in your hand and these cards are sorted.  You are given exactly one new card.  You have to put it into the correct place so that the cards you are holding are still sorted. Algorithm             Step 1 : Start.           Step 2 : Read all numbers in an array A .           Step 3 : Read Key .           Step 4 : From first position to the end of the array compare key and array element .           Step 5 : If Key < A [ i ] then assign i to pos, and return pos .           Step 6 : From n-1 to pos ...