コード例 #1
0
 /// <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>list after adding element</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);
 }
コード例 #2
0
ファイル: FileOperation.cs プロジェクト: shreyasidnale27/OOPS
        /// <summary>
        /// Reads from file.
        /// </summary>
        /// <returns>List of CompanyShares</returns>
        public static List <SharesOfCompany> ReadFromFile()
        {
            CommercialLinkedlist <SharesOfCompany> sharesLinkedList = new CommercialLinkedlist <SharesOfCompany>();

            if (File.Exists(@"C:\Users\admin\source\repos\Object Orienetd Programming\Object Orienetd Programming\CommercialDataProcessing\SharesOfCompany.json"))
            {
                string jsonData = File.ReadAllText(@"C:\Users\admin\source\repos\Object Orienetd Programming\Object Orienetd Programming\CommercialDataProcessing\SharesOfCompany.json");

                ////Getting List<CompanyShares> object from JsonFile.
                List <SharesOfCompany> jsonObjectArray = JsonConvert.DeserializeObject <List <SharesOfCompany> >(jsonData);

                ////Adding All the CompanyShares Object to CustomLinkedLsit.
                foreach (SharesOfCompany cs in jsonObjectArray)
                {
                    sharesLinkedList.AddNodeAtLast(cs);
                }

                return(jsonObjectArray);
            }
            else
            {
                Console.WriteLine("Specified file path does not exist");
                return(new List <SharesOfCompany>());
            }
        }
コード例 #3
0
 /// <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>list after adding node</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);
 }