Making own linear list

Discussion in 'C#' started by plowc, Mar 8, 2011.

  1. plowc

    plowc New Member

    Joined:
    Mar 8, 2011
    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    0
    Hello everyone,

    I am new to this forum. I have a sort of simple task to do with the C#, well it looks like it is not so simple. I have to create my own CLinearList that has only CNodeLong and CNodeString elements in it. I thought I could solve this like it is writtens down below but the code does not work, it compiles, it runs but nothing is written in console.
    I use Microsoft Visual Studio.
    I think I am lost because i don't know what else can I do with the code.
    If anyone can help me, I would appriciate it :)


    CODE:
    --------------------------------------------------------------------------------------------
    Code:
    using System;
    using System.Collections.Generic;
    
    
    namespace Naloga2
    {
        class CNode
        {
            private CNode next;
    
            public CNode getNext()
            {
                return next;
            }
            public void setNext(CNode input)
            {
                next = input;
            }
    
            public CNode()
            {
                next = null;
            }
    
            public virtual void Print()
            {
    
            }
        }
        
    
        class CNodeLong : CNode
        {
            private long vrednost;
    
            public long getVrednost()
            {
                return vrednost;
            }
            public void setVrednost(long input)
            {
                vrednost = input;
            }
    
            public CNodeLong()
            {
    
            }
    
            public CNodeLong(long val)
            {
                vrednost = val;
            }
    
            new public virtual void Print()
            {
                Console.WriteLine(vrednost);
            }
        }
    
        
        unsafe class CNodeString : CNode
        {
            private char* vrednost;
    
            public char* getVrednost()
            {
                return vrednost;
            }
            public void setVrednost(char* input)
            {
                if (vrednost != null)
                {
                    vrednost = null;
                }
                vrednost = input;
            }
    
            public CNodeString()
            {
            }
    
            public CNodeString(char* val)
            {
                vrednost = val;
            }
    
            public virtual void print()
            {
                Console.WriteLine(*vrednost);
            }
        }
    
    
    
    
        class CLinearList
        {
            private CNode FirstElement;
            private CNode endElement;
            private CNode tmp;
    
            public void Add(CNodeLong input)
            {
                tmp = new CNodeLong();
                tmp = input;
                endElement.setNext(tmp);
                endElement = endElement.getNext();
                tmp = null;
            }
    
            public void Add(CNodeString input)
            {
                tmp = new CNodeString();
                tmp = input;
                endElement.setNext(tmp);
                endElement = endElement.getNext();
                tmp = null;
            }
    
            public CNode Get()
            {
                if (tmp != null)
                    tmp = null;
                tmp = FirstElement;
                FirstElement = FirstElement.getNext();
                tmp.setNext(null);
                return tmp;
            }
    
            public void Print()
            {
                tmp = FirstElement;
                while (tmp != null)
                {
                    tmp.Print();
                    tmp = tmp.getNext();
                }
                tmp = null;
            }
    
            public CLinearList()
            {
                FirstElement = new CNode();
                endElement = new CNode();
                tmp = null;
            }
    
            public CLinearList(CNode input)
            {
                FirstElement = new CNode();
                FirstElement = input;
                tmp = null;
            }
    
    
    
    
                
            unsafe public static void Main(String[] args)
            {
                CLinearList seznam = new CLinearList();
                seznam.Add(new CNodeLong(1234));
                seznam.Add(new CNodeLong(53425));
                seznam.Add(new CNodeLong(666));
    
                seznam.Print();
                seznam.Get();
                seznam.Print();
    
                //Console.WriteLine("Ole");
    
            }
    
        }
    
    }
     
    Last edited by a moderator: Mar 8, 2011

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice