(In System.Collections namespace.) -
ArrayList, BitArray, HashTable, SortedList, Queue ,Stack, Linked List etc
STACK
Stack class is generally referred to as LIFO (Last In First Out). They are used mostly in recursive functions.The best example where a stack is used would be to solve expressions.The methods used are-
push()-Adds the element at the top of the stack,
pop()- Removes the element from the top of the stack,
ToString()- Returns a string that represents the current object.
Peek()- Just presents the element.
Mechanism of stack -
Infix- (2+4)*(6/5)-12
Postfix- 24+65/*12-
1. read() 2 - push (2)
2. read() 4 push (4)
3. read - + --> opd2 = pop() opd1=pop()
res = opd1 opt opd2 push (res) // res= 6
4. read() 6 - push (6)
5. read() 5 push (5)
6. read - / --> opd2 = pop() opd1=pop()
res = opd1 opt opd2 push (res) // res= 1(6/5)
7. read() *- opd2 = pop() opd1=pop()
res = opd1 opt opd2 push (res) // res= 6 (6*1)
8. read() 12 - push (12)
9. read() - opd2 = pop() opd1=pop()
res = opd1 opt opd2 push (res) // res= -6 (6-12)
QUEUE
A queue is referred to as FIFO (First in First Out).
Methods used are- Enqueue(), Dequeue(). Peek() etc.
Best example woul dbe a Printer Service.
Array -- int[] intArray = new int[3]; Have to define the size.
Array List --
ArrayList myList = new ArrayList();
An ArrayList is better than Array to use when you have no knowledge in advance about elements number.
ArrayList are slower than Arrays. So, if you need efficiency try to use Arrays.
LinkedList -- in each record/node there is a field that contains a reference (i.e., a link) to the next record in the sequence. It can be single - having one way reference por Double - Having reference to the previous & the next reference.
linkedlist is much more flexible and lets you insert, add and remove elements from both sides of your collection - it can be used as queue and even double-ended queue!