//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); }
public StockList MergeList(StockList listToMerge) { StockList resultList = new StockList(); // write your implementation here StockNode node = this.head; while (node != null) { resultList.AddLast(node.StockHolding); node = node.Next; } node = listToMerge.head; while (node != null) { resultList.AddLast(node.StockHolding); node = node.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 // Added more changes to code public StockList MergeList(StockList listToMerge) { StockList resultList = new StockList(); // write your implementation here //merging two lists using the while conditional statement StockNode node = this.head; while (node != null) { resultList.AddLast(node.StockHolding); node = node.Next; } node = listToMerge.head; while (node != null) { resultList.AddLast(node.StockHolding); node = node.Next; } // returning final list 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); }
//@author: qing qi //param : NA //summary : Sort the list alphabatically //return : NA //return type : NA public void SortByName() { StockNode currentNode = this.head; StockList result = new StockList(); StockNode previousNode = null; for (; currentNode != null; currentNode = currentNode.Next) { StockNode resultNode = result.head; while (true) { if (resultNode == null) { result.AddLast(currentNode.StockHolding); break; } else if (currentNode.StockHolding.Name.CompareTo(resultNode.StockHolding.Name) < 0)//compare the name alphabatically { //if the the previous node of current Node is the the first node, added it to the first if (resultNode == result.head) { result.AddFirst(currentNode.StockHolding); } else { result.AddBefore(currentNode.StockHolding, resultNode, previousNode); } break; } else { previousNode = resultNode;// keep the location o the previousNode resultNode = resultNode.Next; } } } this.head = null; this.head = result.head; }
//@author: qing qi //param : NA //summary : Sort the list by descending number of holdings //return : NA //return type : NA public void SortByValue() { StockNode currentNode = this.head; StockList result = new StockList(); StockNode previousNode = null; for (; currentNode != null; currentNode = currentNode.Next) { StockNode resultNode = result.head; while (true) { if (resultNode == null) { result.AddLast(currentNode.StockHolding); break; } else if (currentNode.StockHolding.Holdings > resultNode.StockHolding.Holdings)//compare holding value { //if the the previous node of current Node is the the first node, added it to the first if (resultNode == result.head) { result.AddFirst(currentNode.StockHolding); } else// if the previous node of current Node is not first node, added it to the location before the current node { result.AddBefore(currentNode.StockHolding, resultNode, previousNode); } break; } else { previousNode = resultNode;// keep the location o the previousNode resultNode = resultNode.Next; } } } this.head = null; this.head = result.head; }
//Rahil Shaik //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(); //Setting current node as head StockNode currentNode = this.head; //Appending current Stocknode to result set resultList.head = currentNode; //Assigninbg current to head to listtomerge for merging currentNode = listToMerge.head; //Checking if the list has any value if (listToMerge != null) { while (currentNode != null) { //Adding each stockholding value to the resultlist resultList.AddLast(currentNode.StockHolding); currentNode = currentNode.Next; } } return(resultList); }