Esempio n. 1
0
 public void DeleteNodes (int howMany, int ThreadId)
 {
     //Deletes howMany nodes from the linked list
     for (int i = 0; i < howMany; i++)
     {
         m_pHead = Delete(m_pHead, m_Random.Next(10));
     }
     Console.WriteLine("Thread {0} Deleted {1} Nodes", ThreadId, howMany);
 }
Esempio n. 2
0
 public void AddNodes (int howMany, int ThreadId)
 {
     //Adds howMany nodes to the linked list
     for (int i = 0; i < howMany; i++)
     {
         m_pHead = Insert(m_pHead, m_Random.Next(10));
     }
     Console.WriteLine("Thread {0} Added {1} Nodes", ThreadId, howMany);
 }
Esempio n. 3
0
 private Node Delete(Node head, int element)
 {
     if(head == null)
     {
         return head;                                                //Node not found
     }
     if (element == head.m_data)                                 //if it was the first data (node)
     {
         return head.m_pNext;
     }
     head.m_pNext = Delete(head.m_pNext, element);               //Recurse to the next element
     return head;                                                // in the list
 }
Esempio n. 4
0
        private Node Insert(Node head, int element)
        {

            if(head == null)                                            //if is NULL make a new node
            {                                                           //and copy number to the new node
                head=new Node();                                        //make new node
                head.m_data = element;                                  //copy number
                head.m_pNext=null ;                                     //set the next to NULL
            }
            else
            {
                Node temp;
                temp = new Node();                                      //Add the new node as the head
                temp.m_data = element;
                temp.m_pNext = head;
                head = temp;
            }
            return head;
        }
Esempio n. 5
0
 public void Empty (int ThreadId)
 {
     Console.WriteLine("Thread {0}: List Empty", ThreadId);
     m_pHead = null;
 }
Esempio n. 6
0
 public LinkedList(int ThreadId)
 {
     m_pHead = null;
     m_Random = new Random();
     // console synchronization Console.SetOut(TextWriter.Synchronized(Console.Out));
 }