Beispiel #1
0
        public void addatfirst(int e)
        {
            NODE addf = new NODE(e);

            addf.data   = e;
            addf.next   = header.next;
            header.next = addf;
            //Console.WriteLine("{0}",e);
        }
Beispiel #2
0
 public void TRAVERSE(NODE E)
 {
     E = header;
     while (E.next != null)
     {
         Console.WriteLine(E.next.data);
         E = E.next;
     }
 }
Beispiel #3
0
        public NODE getlastnode()
        {
            NODE temp = header;

            while (temp.next != null)
            {
                temp = temp.next;
            }
            return(temp);
        }
Beispiel #4
0
        public void print()
        {
            NODE current = new NODE();

            current = header;


            while (current.next != null)
            {
                Console.WriteLine(current.next.data);
                current = current.next;
            }
        }
Beispiel #5
0
        public NODE search(int e)
        {
            NODE t = header;

            while (t != null)
            {
                if (t.data == e)
                {
                    Console.WriteLine("Data is found");
                    return(t);
                }

                t = t.next;
            }
            return(null);
        }
Beispiel #6
0
        public void addatlast(int j)
        {
            //NODE temp = header;
            //while(temp.next!=null)
            //{
            //    temp = temp.next;
            //}
            NODE addl = new NODE(j);

            if (header == null)
            {
                header = addl;
                return;
            }
            NODE lastnode = getlastnode();

            lastnode.next = addl;
        }
Beispiel #7
0
        public void insertafter(int e, int x)
        {
            //if(prevnode==null)
            //{
            //    Console.WriteLine("Previous node cannnot be null");
            //    return;
            //}
            NODE inafter = search(x);

            while (inafter != null)
            {
                NODE n = new NODE(e);
                n.next       = inafter.next;
                inafter.next = n;
            }
            //inafter.next = prevnode.next;
            //prevnode.next = inafter;
        }
Beispiel #8
0
        public void deletenodebykey(int i)
        {
            NODE temp = header;
            NODE prev = null;

            if (temp != null && temp.data == i)
            {
                header = temp.next;
                return;
            }
            while (temp != null && temp.data != i)
            {
                prev = temp;
                temp = temp.next;
            }
            if (temp == null)
            {
                Console.WriteLine("NOT DELETING ITEM");
                return;
            }
            prev.next = temp.next;
        }
Beispiel #9
0
 public singlelinklist()
 {
     header = new NODE();
 }
Beispiel #10
0
 public NODE(int d)
 {
     data = d;
     next = null;
 }
Beispiel #11
0
 public NODE()
 {
     data = 0;
     next = null;
 }