//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);
        }
Ejemplo n.º 2
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 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)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);
        }
        //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);
        }
Ejemplo n.º 5
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 mergedList = new StockList();
            StockNode currentOne = this.head;
            StockNode currentTwo = listToMerge.head;

            // traverse the first list till the end and add the nodes to merged list
            while (currentOne != null)
            {
                mergedList.AddStock(currentOne.StockHolding);
                currentOne = currentOne.Next;
            }
            // traverse the second list till the end, also add the nodes to merged list
            while (currentTwo != null)
            {
                mergedList.AddStock(currentTwo.StockHolding);
                currentTwo = currentTwo.Next;
            }

            return(mergedList);
        }
Ejemplo n.º 7
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

            // Check for empty list
            if (this.IsEmpty())
            {
                Console.WriteLine("List is empty!");
            }
            else
            {
                //Assign head pointer to the first stocklist
                StockNode current_1 = this.head;
                while (current_1 != null)
                {
                    resultList.AddStock(current_1.StockHolding);
                    current_1 = current_1.Next;
                }
            }
            if (this.IsEmpty())
            {
                Console.WriteLine("List is empty!");
            }
            else
            //head of the mergelist is assigned to pointer of the second stocklist
            {
                StockNode current_2 = listToMerge.head;
                while (current_2 != null)
                {
                    resultList.AddStock(current_2.StockHolding);
                    current_2 = current_2.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);
        }
Ejemplo n.º 9
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);
        }
Ejemplo n.º 10
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();
            StockList currentStockList = this;

            StockNode current     = this.head;
            StockNode nodeToMerge = listToMerge.head;


            while (nodeToMerge != null)
            {
                currentStockList.AddStock(nodeToMerge.StockHolding);

                nodeToMerge = nodeToMerge.Next;
            }

            currentStockList.SortByName();

            resultList = currentStockList;

            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)
        {
            //Already a part of the method
            StockList resultList = new StockList();

            resultList = this;


            // write your implementation here

            StockNode currentNode = head;

            while (currentNode != null & listToMerge.head != null)
            {
                resultList.AddStock(listToMerge.head.StockHolding);
                listToMerge.head = listToMerge.head.Next;
                currentNode      = currentNode.Next;
            }

            //Already a part of the method
            return(resultList);
        }