- when share of common stock of some company is soldthe capital gain (orsometimeslossis the difference between the share' selling price and the price originally paid to buy it this rule is easy to understand for single sharebut if we sell multiple shares of stock bought over long period of timethen we must identify the shares actually being sold standard accounting principle for identifying which shares of stock were sold in such case is to use fifo protocol--the shares sold are the ones that have been held the longest (indeedthis is the default method built into several personal finance software packagesfor examplesuppose we buy shares at $ each on day shares at $ on day shares at $ on day and then sell shares on day at $ each then applying the fifo protocol means that of the shares sold were bought on day were bought on day and were bought on day the capital gain in this case would therefore be (- )or $ write program that takes as input sequence of transactions of the form "buy share(sat eachor "sell share(sat each,assuming that the transactions occur on consecutive days and the values and are integers given this input sequencethe output should be the total capital gain (or lossfor the entire sequenceusing the fifo protocol to identify shares - design an adt for two-colordouble-stack adt that consists of two stacks--one "redand one "blue"--and has as its operations color-coded versions of the regular stack adt operations for examplethis adt should support both red push operation and blue push operation give an efficient implementation of this adt using single array whose capacity is set at some value that is assumed to always be larger than the sizes of the red and blue stacks combined notes we were introduced to the approach of defining data structures first in terms of their adts and then in terms of concrete implementations by the classic books by ahohopcroftand ullman [ exercises - and - are similar to interview questions said to be from well-known software company for further study of abstract data typessee liskov and guttag [ ]cardelli and wegner [ ]or demurjian [