Zk 12.2.2009 (yoyo check it out :)

Odeslat odpověď

Smajlíci
:D :) :( :o :shock: :? 8) :lol: :x :P :oops: :cry: :evil: :twisted: :roll: :wink: :!: :?: :idea: :arrow: :| :mrgreen:

BBCode je zapnutý
[img] je zapnutý
[flash] je vypnutý
[url] je zapnuté
Smajlíci jsou zapnutí

Přehled tématu
   

Rozšířit náhled Přehled tématu: Zk 12.2.2009 (yoyo check it out :)

Re: Zk 12.2.2009 (yoyo check it out :)

od Jonáš » 7. 2. 2011 16:07

What can interface I1 enforce?

Kód: Vybrat vše
a) operator *
b) public method
c) private method
d) internal method
e) interface I2
f) indexer []
g) static property

b), f) ... more?
Není správně i e) interface I2?
Pokud I1 dědí od I2, třída implementující I1 musí implementovat i vše co delkaruj I2.
Je v nějakých případech rozdíl, jestli třída A imlementuje I1 který dědí od I2 nebo A implementuje přímo I1 a I2?

Re: Zk 12.2.2009 (yoyo check it out :)

od Tempest » 7. 2. 2010 17:17

Kód: Vybrat vše

 public void Enqueue(T item, P prio)
            {
                Node n = new Node(item, prio);
                lock (this)
                {
                    if (first == null)
                        first = n;
                    else
                    {
                        Node cur = first;
                        Node prev = null;
                        while (cur != null && prio.CompareTo(cur.prio) <= 0)
                        {
                            prev = cur;
                            cur = cur.next;
                        }
                        prev.next = n;
                        if (cur != null)
                            cur.prev = n;
                    }
                }
            }
Jen pro pořádek, to lock(this) je špatně, už to tu párkrát bylo (např. http://forum.matfyz.info/viewtopic.php?f=421&t=5004).

Zk 12.2.2009 (yoyo check it out :)

od Santhos » 12. 2. 2009 19:53

Hey,

sup fellows? Lets rock:
4120, 4096, 4104,...?

Kód: Vybrat vše

(24 | 4096) & (~(1 << 4))
4104
a) nezkompiluje se
b) 1,2
c) , (tedy pouze znak carka)
d) runtime error recpectively Exception

Kód: Vybrat vše

class Plus {
    public static void AddPlus() {
        Prg.AddOp("+",1);
    }
}

class Divide {
    public static void AddDivide() {
        Prg.AddOp("/",2);
    }
}

class Prg {
    static Dictionary<string, int> d=new Dictionary<string, int>();

    public static void AddOp(string s, int i) {
        d.Add(s,i);
    }

    static void Main() {                       
        Console.WriteLine(string.Format("{0},{1}",d["+"],d["-"]));
        new Plus();
        new Divide();
    }
}
d)
4B, 8B, 32B, 64B, 2^32, 2^64B, platform dependent? // B = Byte

Kód: Vybrat vše

size of long
8B
cannot be compiled, 32, 25... dunno actually

Kód: Vybrat vše

delegate int F();
... a very nice code
?
System.Object, object, decimal, some class, System.Int64

Kód: Vybrat vše

value types
decimal, System.Int64
What can interface I1 enforce?

Kód: Vybrat vše

a) operator *
b) public method
c) private method
d) internal method
e) interface I2
f) indexer []
g) static property
b), f) ... more?
Write 2 of the main reasons why to use immutable classes:

1) Immutable classes are thread safe
2) They can be used as hash values in hash tables such as Dictionary

http://codebetter.com/blogs/patricksmac ... -them.aspx
Implement enque in priority queue made of doubly-linked list. Make it safe to use in any context (besides thread safe, exceptions).

Kód: Vybrat vše

class Queue<T, P>
        {
            _____Node
            {
                public Node prev, next;
                public T item;
                public P prio;
                public Node(T i, P p) { item = t; prio = p; }
            }

            public void Enqueue(T item, P prio)
            {
                Node n = new Node(item, prio);


            }

            public T Dequeue()
            {
                 ...  // count on correct implementation
            }
        }
Answer:

Kód: Vybrat vše

class Queue<T, P> where P:IComparable<P>
        {
            class Node
            {
                public Node prev, next;
                public T item;
                public P prio;
                public Node(T i, P p) { item = t; prio = p; }
            }

            Node first = null;

            public void Enqueue(T item, P prio)
            {
                Node n = new Node(item, prio);
                lock (this)
                {
                    if (first == null)
                        first = n;
                    else
                    {
                        Node cur = first;
                        Node prev = null;
                        while (cur != null && prio.CompareTo(cur.prio) <= 0)
                        {
                            prev = cur;
                            cur = cur.next;
                        }
                        prev.next = n;
                        if (cur != null)
                            cur.prev = n;
                    }
                }
            }

            public T Dequeue()
            {
                 ...
            }

!NO WARRANTY GUARANTEED!

Nahoru