/// <summary> /// Adds the node at last1. /// </summary> /// <param name="list">The list.</param> /// <param name="data">The data.</param> /// <param name="list1">The list1.</param> /// <returns>returning the commercial linked list</returns> public CommercialLinkedList <T> AddNodeAtLast1(List <T> list, T data, CommercialLinkedList <T> list1) { try { if (this.IsEmpty()) { this.head = new Node <T>(data, null, null); this.nodeCount++; return(list1); } else { Node <T> currentNode = this.head; Node <T> newNode = new Node <T>(data, null); while (currentNode.GetNext() != null) { currentNode = currentNode.GetNext(); } currentNode.SetNext(newNode); this.nodeCount++; } } catch (Exception ex) { Console.WriteLine(ex.Message); } return(list1); }
/// <summary> /// Reads List of Share /// </summary> /// <returns>returns shareList</returns> public static List <ShareList> ReadFromFile() { CommercialLinkedList <ShareList> sharedLinkedList = new CommercialLinkedList <ShareList>(); if (File.Exists(@"C:\Users\Admin\source\repos\OOPSProgramming\OOPSProgramming\CommercialDataProcessing\StockAccount.json")) { string jsonData = File.ReadAllText(@"C:\Users\Admin\source\repos\OOPSProgramming\OOPSProgramming\CommercialDataProcessing\StockAccount.json"); ////Getting List<CompanyShares> object from JsonFile. List <ShareList> jsonObjectArray = JsonConvert.DeserializeObject <List <ShareList> >(jsonData); ////Adding All the CompanyShares Object to CustomLinkedLsit. foreach (ShareList sl in jsonObjectArray) { sharedLinkedList.AddNodeAtLast(sl); } return(jsonObjectArray); } else { Console.WriteLine("specified File path does not exists"); return(new List <ShareList>()); } }
/// <summary> /// Adds the node at first1. /// </summary> /// <param name="list">The list.</param> /// <param name="data">The data.</param> /// <param name="list1">The list1.</param> /// <returns>returning the list</returns> public CommercialLinkedList <T> AddNodeAtFirst1(List <T> list, T data, CommercialLinkedList <T> list1) { try { if (this.IsEmpty()) { this.head = new Node <T>(data, null); return(list1); } else { Node <T> newNode = new Node <T>(data, null); newNode.SetNext(this.head); this.head = newNode; } } catch (Exception ex) { Console.WriteLine(ex.Message); } return(list1); }