//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;
            //Initializing two variables temp and temp1 to head of client 1 and 2 portfolio respectively
            StockNode temp  = head;
            StockNode temp1 = listToCompare.head;

            //Outer loop to traverse through client 1 portfoli0
            while (temp != null)
            {
                temp1 = listToCompare.head;
                //Inner loop to traverse through client 2 portfoli0
                while (temp1 != null)
                {
                    if (temp.StockHolding.Symbol == temp1.StockHolding.Symbol)
                    {
                        similarityIndex++;
                        break;
                    }
                    temp1 = temp1.Next;
                }
                temp = temp.Next;
            }
            return(similarityIndex);
        }
示例#2
0
        public static void Main(string[] args)
        {
            Stock stockOne   = new Stock("GOOG", "Google", 1.2m, 6.27m);
            Stock stockTwo   = new Stock("MSFT", "Microsoft", 5m, 111.2m);
            Stock stockThree = new Stock("AAPL", "Apple", 6m, 222.7m);
            Stock stockFour  = new Stock("AMZN", "Amazon", 1.2m, 198.7m);
            Stock stockFive  = new Stock("Z", "Zillow", 2.4m, 207.6m);
            Stock stockSix   = new Stock("B", "Barnes ", 2.2m, 68.7m);
            Stock stockSeven = new Stock("GOOG", "Google", 3.6m, 115.3m);
            Stock stockEight = new Stock("AAPL", "Apple", 5m, 147.6m);
            Stock stockNine  = new Stock("GOOG", "Google", 1.2m, 6.27m);

            ClientPortfolio client1 = new ClientPortfolio("Andrew", "Mountain View", "555-111-9070");

            client1.StockList.AddStock(stockOne);
            client1.StockList.AddStock(stockTwo);
            client1.StockList.AddStock(stockThree);
            client1.StockList.AddStock(stockFour);
            client1.StockList.AddStock(stockNine);

            Console.WriteLine("************" +
                              "**************Client-1 Portfolio*****************************************");
            client1.StockList.Print();
            Console.WriteLine("Number of shares :" + client1.StockList.Length());
            Console.WriteLine("Current value of portfolio for client 1 :" + client1.GetPortfolioValue());
            Console.WriteLine("Stock with most shares for client 1:" + client1.StockList.MostShares());
            client1.StockList.SortByValue();
            Console.WriteLine("Portfolio sorted in descending order by number of holdings for client 1:");
            client1.StockList.Print();


            Console.WriteLine("**************************Client-2 Portfolio*****************************************");
            ClientPortfolio client2 = new ClientPortfolio("Chris", "New York", "435-111-000");

            client2.StockList.AddStock(stockFive);
            client2.StockList.AddStock(stockSix);
            client2.StockList.AddStock(stockSeven);
            client2.StockList.AddStock(stockEight);

            client2.StockList.Print();
            Console.WriteLine("Number of shares :" + client2.StockList.Length());
            Console.WriteLine("Current value of portfolio for client 2 :" + client2.GetPortfolioValue());
            Console.WriteLine("Stock with most shares for client 2 :" + client2.StockList.MostShares());
            client2.StockList.SortByValue();
            Console.WriteLine("Portfolio sorted in descending order by number of holdings for client 2:");
            client2.StockList.Print();
            client2.StockList.SortByName();
            Console.WriteLine("Portfolio sorted in alphabatical order for client 2:");
            client2.StockList.Print();
            Console.WriteLine();

            Console.WriteLine("Similarity Index for Client-1 and Clien-2 :" + client1.StockList.Similarity(client2.StockList));

            Console.WriteLine("**************************Client-1,Client -2 Merged Portfolio*****************************************");
            StockList mergedPortfolio = client1.StockList.MergeList(client2.StockList);

            mergedPortfolio.Print();

            Console.ReadLine();
        }
示例#3
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;

            var firstCurrent  = this.head;
            var tempFirst     = firstCurrent;
            var secondCurrent = listToCompare.head;
            var tempSecond    = secondCurrent;

            while (firstCurrent != null)
            {
                while (secondCurrent != null)
                {
                    if (Assn2_Utility.Compare(secondCurrent.StockHolding, firstCurrent.StockHolding))
                    {
                        similarityIndex += 1;
                    }

                    secondCurrent = secondCurrent.Next;
                }

                firstCurrent  = firstCurrent.Next;
                secondCurrent = tempSecond;
            }


            return(similarityIndex);
        }
        //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 here1
            // Added by Manasa - start of code
            //assigning the stock of the client who called the function merge
            StockNode current = this.head;

            // that first list to be merged is assigned to the new stocklist -which holds the merged list
            resultList.head = current;

            Stock stockToAdd = listToMerge.head.StockHolding;

            while (listToMerge.head != null)
            {
                // this function call adds each stock to the stocklist -resultList
                //while also trying to merge any existing stock with their holdings
                resultList.AddStock(listToMerge.head.StockHolding);
                // to traverse the stocklist to the next node
                listToMerge.head = listToMerge.head.Next;
            }
            //Added by Manasa - end of code
            return(resultList);
        }
        //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;
            //setup stocknode one & two, in order to record two different lists
            StockNode currentone = this.head;
            StockNode currenttwo = listToCompare.head;

            while (currentone != null)
            {
                while (currenttwo != null)
                {
                    string currentname = currentone.StockHolding.Name;
                    string comparename = currenttwo.StockHolding.Name;
                    if (currentname.CompareTo(comparename) == 0)
                    {
                        similarityIndex++;
                    }
                    currenttwo = currenttwo.Next;
                }
                currenttwo = listToCompare.head;
                currentone = currentone.Next;
                //traverse the loop till the end, find similarity in two different lists
            }

            return(similarityIndex);
        }
示例#6
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
            StockList tempStockList = new StockList();

            //tempStockList = this;

            while (tempStockList.head != null && listToCompare.head != null)
            {
                if (tempStockList.head.StockHolding.Symbol == listToCompare.head.StockHolding.Symbol)
                {
                    // listToCompare.head = listToCompare.head.Next;
                    similarityIndex++;
                }



                tempStockList.head = tempStockList.head.Next;
                listToCompare.head = listToCompare.head.Next;
                similarityIndex++;
            }

            return(similarityIndex);
        }
        //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();

            if (this.IsEmpty())
            {
                Console.WriteLine("List is Empty");
            }
            else
            {
                StockNode c1 = this.head;
                while (c1 != null)
                {
                    resultList.AddStock(c1.StockHolding);
                    c1 = c1.Next;
                }
                StockNode c2 = listToMerge.head;
                while (c2 != null)
                {
                    resultList.AddStock(c2.StockHolding);
                    c2 = c2.Next;
                }
            }
            return(resultList);
        }
        //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();
            StockNode mergeNode  = null;

            //Sort the first list by name and assign the list to the result list.
            if (this.Length() > 0)
            {
                this.SortByName();
                resultList = this;
            }

            // Traverse through each node and add to the end of the node.
            if (listToMerge.Length() > 0)
            {
                mergeNode = listToMerge.head;
                while (mergeNode != null)
                {
                    resultList.AddStock(mergeNode.StockHolding);
                    mergeNode = mergeNode.Next;
                }
            }

            return(resultList);
        }
示例#9
0
 // default constructor
 public ClientPortfolio()
 {
     StockList     = new StockList();
     HolderName    = null;
     HolderAddress = null;
     ContactNumber = null;
 }
        //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 current;

            current = this.head;

            StockNode secondList;

            secondList = listToCompare.head;


            while (current != null)
            {
                while (secondList != null)
                {
                    if (current.StockHolding.Symbol == secondList.StockHolding.Symbol)
                    {
                        similarityIndex++;
                        //break;
                    }
                    secondList = secondList.Next;
                }

                secondList = listToCompare.head;


                current = current.Next;
            }



            return(similarityIndex);
        }
示例#11
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);
        }
示例#12
0
        //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;

            // write your implementation here and check
            StockNode current = this.head;
            StockNode compare = listToCompare.head;

            if (current.StockHolding.Name.Equals(compare.StockHolding.Name))
            {
                similarityIndex = similarityIndex + 1;
            }

            //For each Stocknode in list, compare to the previous to see who has greater holdings
            while (current.Next != null)
            {
                current = current.Next;
                compare = listToCompare.head;
                if (current.StockHolding.Name.Equals(compare.StockHolding.Name))
                {
                    similarityIndex = similarityIndex + 1;
                }

                while (compare.Next != null)
                {
                    compare = compare.Next;
                    if (current.StockHolding.Name.Equals(compare.StockHolding.Name))
                    {
                        similarityIndex = similarityIndex + 1;
                    }
                }
            }

            return(similarityIndex);
        }
示例#13
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)
        {
            StockNode current = this.head;


            head = current;

            StockNode merge = listToMerge.head;

            //We go to the end of the first list that is going to be merged
            while (current.Next != null)
            {
                current = current.Next;
            }

            current.Next = merge; // This is how we combine both lists

            current = this.head;

            StockList ResultList = new StockList();

            ResultList.head = current;



            return(ResultList);
        }
示例#14
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
        }
示例#15
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

            return(similarityIndex);
        }
示例#16
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

            return(resultList);
        }
示例#17
0
 // Construtor for initialization
 public ClientPortfolio(string holderName, string holderAddress, string contactNumber)
 {
     StockList      = new StockList();
     PortfolioValue = 0.0m;
     HolderName     = holderName;
     HolderAddress  = holderAddress;
     ContactNumber  = contactNumber;
 }
示例#18
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)
        {
            //Three preliminary variables are introduced. “resultList” is a new
            //StockList which will hold what will be the final merged list of stocks.
            //StockNode “current1” initializes the list of nodes to be cycled through, and
            //StockNode “current2” initializes the beginning of 2nd list of nodes. The end
            //result will produce a merged list of these two lists of nodes.


            StockList resultList = new StockList();
            StockNode current1   = this.head;
            StockNode current2   = listToMerge.head;

            //An “if- else if - else if - else” statement is introduced which cycles
            //through depending on if “current1” and “current2” hold null values or
            //not.The presence of a null value for either will return a new updated
            //value for resultList based on either list.Within the else statement is a
            //while loop for both StockNodes, which cycles through the nodes and adds
            //them to the resultList using the AddStock() function found in StockList_Students_1.

            if (current1 == null && current2 == null)
            {
                return(resultList);
            }
            else if (current1 == null)
            {
                resultList = listToMerge;
                return(resultList);
            }
            else if (current2 == null)
            {
                resultList = this;
                return(resultList);
            }
            else
            {
                while (current1 != null)
                {
                    resultList.AddStock(current1.StockHolding);
                    current1 = current1.Next;
                }
                resultList.SortByName();
                while (current2 != null)
                {
                    resultList.AddStock(current2.StockHolding);
                    current2 = current2.Next;
                }
                resultList.SortByName();

                //Finally, the SortByName() function, also referenced from StockList_Students_1,
                //is used to sort all of the stocks into appropriate alphabetical order, once they
                //are present within the final resultList.

                return(resultList);
            }
        }
        //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);
            }
        }
示例#20
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
        }
示例#21
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


        // use AddStock function and Count functions as helpers
        // 1. Sort lists by name
        // 2. determine count of elements in each list
        // 3.  Pick as main list the larger list
        // 4.  Loop through the other list and add stock using add stock function
        // 5.  return new list


        public StockList MergeList(StockList listToMerge)
        {
            this.SortByName();
            StockList resultList = this;


            StockNode currentNode = listToMerge.head;



            for (int i = 0; i < listToMerge.Length(); i++) //loop through list to merge
            {
                this.AddStock(currentNode.StockHolding);
                currentNode = currentNode.Next;
            }


            return(resultList);
        }
        //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

            StockNode current  = this.head;
            StockNode previous = this.head;

            while (current != null)
            {
                Stock currentStock = current.StockHolding;
                resultList.AddStock(currentStock);
                previous = current;
                current  = current.Next;
            }

            return(resultList);
        }
示例#23
0
        //@author: qing qi
        //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();
            StockNode stockNode  = this.head;

            for (; stockNode != null; stockNode = stockNode.Next)
            {
                if (listToMerge.Contains(stockNode.StockHolding) == null)
                {
                    listToMerge.AddStock(stockNode.StockHolding);
                }
                else
                {
                    continue;
                }
            }
            resultList = listToMerge;
            return(resultList);
        }
示例#24
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();
            StockNode current    = listToMerge.head;

            while (current != null)
            {
                resultList.AddStock(current.StockHolding);
                current = current.Next;
            }

            while (this.head != null)
            {
                resultList.AddStock(this.head.StockHolding);
                this.head = this.head.Next;
            }

            return(resultList);
        }
        //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();
            StockNode currentOne = this.head;
            StockNode currentTwo = listToMerge.head;

            while (currentOne != null)
            {
                //resultList.AddStock(currentOne.StockHolding);  //A bug in mergeList()
                while (currentTwo != null)
                {
                    resultList.AddStock(currentTwo.StockHolding);
                    currentTwo = currentTwo.Next;
                }
                resultList.AddStock(currentOne.StockHolding);
                currentOne = currentOne.Next;
            }
            return(resultList);
        }
示例#26
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();

            resultList = this;
            StockNode startOfList = listToMerge.head;

            // traverse the list till the end
            StockNode current = resultList.head;

            while (current.Next != null)
            {
                current = current.Next;
            }

            // point the last node of the first list to the new node of the other list
            current.Next = startOfList;

            return(resultList);
        }
        //Shreyas Dalvi
        //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
            StockNode currNd = this.head;

            resultList.head = currNd;
            currNd          = listToMerge.head;
            if (listToMerge != null)
            {
                while (currNd != null)
                {
                    resultList.AddLast(currNd.StockHolding);
                    currNd = currNd.Next;
                }
            }

            return(resultList);
        }
        //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 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 current         = this.head;
            StockNode current2        = listToCompare.head;

            //With two Do-while loops comparing 1st node of List1 with all the nodes of List2,
            //and then comparing 2nd node of List1 with all the nodes of List2
            //and this goes on until head = null
            while (current != null)
            {
                while (current2 != null)
                {
                    if (current.StockHolding.Symbol == current2.StockHolding.Symbol)
                    {
                        //similarity found and checking if that is the last node in the list then adding 1 to it
                        if (current.Next == null || current2.Next == null)
                        {
                            similarityIndex = similarityIndex + 1;
                        }
                        //similarity found and checking if the same stock is present in the same lists,
                        //i.e. if Client 1 or Client 2 has two or more GOOG in their portfolio then for each person
                        //it will be counted once and will eliminate the first GOOG keeping only the last GOOG.
                        else if (current.StockHolding.Symbol == current.Next.StockHolding.Symbol || current2.StockHolding.Symbol == current2.Next.StockHolding.Symbol)
                        {
                            similarityIndex = similarityIndex + 0;
                        }
                        //similarity found and there is no two common stock in each client's
                        //portfolio then add 1 to the similarity index
                        else
                        {
                            similarityIndex = similarityIndex + 1;
                        }
                    }
                    current2 = current2.Next;
                }
                current2 = listToCompare.head;
                current  = current.Next;
            }
            return(similarityIndex);
        }
示例#30
0
        //Rahil Shaik
        //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;
            //Creating an instance for current node
            StockNode currentNode = this.head;

            if (listToCompare != null)
            {
                while (currentNode != null)
                {
                    //Checking if the current stock holding is present in the list
                    if (listToCompare.Contains(currentNode.StockHolding) != null)
                    {
                        //Increasing the index count if it is present
                        similarityIndex += 1;
                    }
                    currentNode = currentNode.Next;
                }
            }
            return(similarityIndex);
        }