Esempio n. 1
0
        //param   (StockList)listToMerge : second list to be merged
        //summary      : merge two different list into a single result list
        //return       : merged list
        //return type  : StockList
        public StockList MergeList(StockList listToMerge)
        {
            StockList resultList = new StockList();

            // write your implementation here

            var list1 = new List <StockNode>();

            if (!this.IsEmpty())
            {
                var stn = new StockNode();
                stn = this.head;
                list1.Add(stn);

                do
                {
                    stn = stn.Next;
                    list1.Add(stn);
                }while (stn.Next != null);
            }

            var list2 = new List <StockNode>();

            if (!listToMerge.IsEmpty())
            {
                var stn = new StockNode();
                stn = listToMerge.head;
                list2.Add(stn);

                do
                {
                    stn = stn.Next;
                    list2.Add(stn);
                }while (stn.Next != null);
            }

            for (int i = 0; i < list1.Count; i++)
            {
                var   symbol       = list1[i].StockHolding.Symbol;
                var   name         = list1[i].StockHolding.Name;
                var   holdings     = list1[i].StockHolding.Holdings;
                var   currentPrice = list1[i].StockHolding.CurrentPrice;
                Stock stock        = new Stock(symbol, name, holdings, currentPrice);

                resultList.AddLast(stock);
            }

            for (int i = 0; i < list2.Count; i++)
            {
                var   symbol       = list2[i].StockHolding.Symbol;
                var   name         = list2[i].StockHolding.Name;
                var   holdings     = list2[i].StockHolding.Holdings;
                var   currentPrice = list2[i].StockHolding.CurrentPrice;
                Stock stock        = new Stock(symbol, name, holdings, currentPrice);

                resultList.AddLast(stock);
            }

            return(resultList);
        }
Esempio n. 2
0
        //param  (StockList) listToCompare     : StockList which has to comared for similarity index
        //summary      : finds the similar number of nodes between two lists
        //return       : similarty index
        //return type  : int
        public int Similarity(StockList listToCompare)
        {
            int similarityIndex = 0;

            StockNode current2 = null;

            if (this.IsEmpty())
            {
                return(0);
            }
            if (listToCompare.IsEmpty())
            {
                return(0);
            }
            StockNode current1 = head;         // head pointer is assigned to the first stocklist

            while (current1 != null)           // traversing through the list until the pointer is pointing to empty location
            {
                current2 = listToCompare.head; //head of the comparable list is assigned to current 2
                while (current2 != null)
                {
                    if (current1.StockHolding.Name == current2.StockHolding.Name) // checking if the value both ponters are pointing to are the same.
                    {
                        similarityIndex = similarityIndex + 1;                    //incrementing the similarity index every ime the stockholding name is the same
                    }
                    current2 = current2.Next;                                     // moving to th epointer to next stock in stocklist until stocklist is empty
                }
                current1 = current1.Next;
            }

            return(similarityIndex);    // count of similar nodes
        }
        //param  (StockList) listToCompare     : StockList which has to comared for similarity index
        //summary      : finds the similar number of nodes between two lists
        //return       : similarty index
        //return type  : int
        public int Similarity(StockList listToCompare)
        {
            // Introduces intial int for similarity index as 0. This is
            // currently a placeholder and will be modified accordingly.

            int similarityIndex = 0;

            // An "if - else" statement is introduced. The if section returns
            // the default value if the lists used for comparison are empty.

            if (this.IsEmpty() || listToCompare.IsEmpty())
            {
                return(similarityIndex);
            }

            // The else statement introduces StockNodes "current1" and "current2".
            // These represent the initial list and the list for comparison to the
            // initial list.

            else
            {
                StockNode current1 = this.head;
                StockNode current2 = listToCompare.head;

                // The While loop works while both lists are not null. While this loop
                // is running, it uses the CompareTo() function to check each currently
                // active node from each list to see if they match or not. The index score
                // then increases if that is the case. It then cycles the two StockNodes
                // to the next node in the list, until no nodes remain.

                while (current1 != null)
                {
                    while (current2 != null)
                    {
                        if (current1.StockHolding.Name.CompareTo(current2.StockHolding.Name) == 0)
                        {
                            similarityIndex++;
                        }
                        current2 = current2.Next;
                    }
                    current2 = listToCompare.head;
                    current1 = current1.Next;
                }

                // Finally, the loop then produces the final similarityIndex. The higher the value
                // in the index, the more similar the two lists are.

                return(similarityIndex);
            }
        }
Esempio n. 4
0
        //param  (StockList) listToCompare     : StockList which has to comared for similarity index
        //summary      : finds the similar number of nodes between two lists
        //return       : similarty index
        //return type  : int
        public int Similarity(StockList listToCompare)
        {
            int similarityIndex = 0;

            // write your implementation here
            //code added by Mano
            var stock1 = new List <string>();

            //checks if the list is empty
            if (!this.IsEmpty())
            {
                StockNode items = this.head;
                stock1.Add(items.StockHolding.Symbol);

                //takes the symbol of each list holding and compares
                while (items.Next != null)
                {
                    stock1.Add(items.StockHolding.Symbol);
                    items = items.Next;
                }
                stock1.Add(items.StockHolding.Symbol);
            }

            var stock2 = new List <string>();

            //list 1 compares to lsit symbols
            if (!listToCompare.IsEmpty())
            {
                var items = new StockNode();
                items = listToCompare.head;
                stock2.Add(items.StockHolding.Symbol);


                while (items.Next != null)
                {
                    stock2.Add(items.StockHolding.Symbol);
                    items = items.Next;
                }
                stock2.Add(items.StockHolding.Symbol);
            }

            var CommonList = stock1.Intersect(stock2);

            similarityIndex = CommonList.Count();


            return(similarityIndex);
            //end of code added by Mano
        }
        //param  (StockList) listToCompare     : StockList which has to comared for similarity index
        //summary      : finds the similar number of nodes between two lists
        //return       : similarty index
        //return type  : int
        public int Similarity(StockList listToCompare)
        {
            int similarityIndex = 0;

            // write your implementation here
            var list1 = new List <string>();

            if (!this.IsEmpty())
            {
                var stn = new StockNode();
                stn = this.head;
                list1.Add(stn.StockHolding.Symbol);

                do
                {
                    stn = stn.Next;
                    list1.Add(stn.StockHolding.Symbol);
                }while (stn.Next != null);
            }

            var list2 = new List <string>();

            if (!listToCompare.IsEmpty())
            {
                var stn = new StockNode();
                stn = listToCompare.head;
                list2.Add(stn.StockHolding.Symbol);

                do
                {
                    stn = stn.Next;
                    list2.Add(stn.StockHolding.Symbol);
                }while (stn.Next != null);
            }

            var CommonList = list1.Intersect(list2);

            similarityIndex = CommonList.Count();

            return(similarityIndex);
        }
        //param  (StockList) listToCompare     : StockList which has to compared for similarity index
        //summary      : finds the similar number of nodes between two lists
        //return       : similarty index
        //return type  : int
        public int Similarity(StockList listToCompare)
        {
            int       similarityIndex       = 0;
            StockNode listToCompareCurrent  = listToCompare.head;
            StockNode listToComparePrevious = null;
            StockNode thisListCurrent       = this.head;
            StockNode thisListPrevious      = null;

            if (listToCompare.IsEmpty() || this.IsEmpty())
            {
                return(similarityIndex);
            }
            else
            {
                while (thisListCurrent != null)
                {
                    while (listToCompareCurrent != null)
                    {
                        if (thisListCurrent.StockHolding.Symbol == listToCompareCurrent.StockHolding.Symbol)
                        {
                            similarityIndex++;

                            listToComparePrevious = listToCompareCurrent;
                            listToCompareCurrent  = listToCompareCurrent.Next;
                        }
                        else
                        {
                            listToComparePrevious = listToCompareCurrent;
                            listToCompareCurrent  = listToCompareCurrent.Next;
                        }
                    }
                    listToCompareCurrent  = listToCompare.head;
                    listToComparePrevious = null;
                    thisListPrevious      = thisListCurrent;
                    thisListCurrent       = thisListCurrent.Next;
                }
                return(similarityIndex);
            }
        }