Sunday, March 15, 2009

Data structures are some objects that we generate to store data in them , these data can be more than one variable ( Arrays can be considered as built in data structures ) They also cotain algorithms to process those stored data .

STACKS
Here's our first data structure , which is called a stack . The most important property of a stack , which makes it different from a queue is that it's is "LIFO : Last input first output " , this looks like placing some copybooks on your desk , and then when you want one of them (assume that they are all simillar ) you've to take the one on the top first which is the last one was placed.

Notes:

* Write an element in stack ... Push.
* Move an element from stack ... Pop.
* Read an element from stack without deleting ... Top.
* IsEmpty and IsFull functions are never used when dynamically allocated stack "Linked Stack".
* The main difference between the stacks and arrays is that arrays have direct access to any element in it.

QUEUES
Here's our Second data structure , which is called a queue . The most important property of a queue , which makes it different from a stack is that it's is "FIFO : First input first output " , it's just like real life queues.
You can think of a queue as a special kind of lists , where items are added from one end , and removed from the other end ; while the elements order is preserved.
We've two types of queues :
(1)Linear queues : in case elements are read from the front , we need to shift ... time delay.
(2)Circular queues : This's the one we're going to implement in this course.

Notes:

There are two methods of implementing the queues :
_Approach one :
We here will initialize " Front = 0 " , and " Rear = -1 " ; and the test for empty queue " Front = = NextPosition(Rear) ? " . But `the main problem here is that this condition also holds for a full queue .
Increase rear then put the value.
Front points to the first element.
Rear points to the last element.
_Approach two :
This is a better one , as we'll let " Front = = Rear ?" indicate an empty queue .
Front points to a never used item , and real data starts from the next position to the front .
Front must always points to an empty cell , and this means that we'll lose a place in memory ( never used cell ) but on the other hand it's make it easier to detect an empty queue .

Linked Lists
A linked list is an alternative method used to store lists of data items so that they are always accessed in the correct sequence. Data items can be added to the list and deleted from the list but it is usually necessary to search through the list one entry at a time until either the required value if found or a greater value is encountered indicating that it is not present.

The linked list consists of a number of data items which are linked using pointers. The pointers contain the location of the next item in the list and may be true pointers in languarges that support pointer types or may be integer values in languages that do not.

The final pointer in the list is a terminator or nul pointer. The start of the list is held in another pointer indicating where the first item in the list is physically stored. Depending on the implementation of the linked list it may also be neccessary to have a free space pointer which is used to indicate where the next data item to be added can be put.

Types of Linked lists

Linearly linked list

Singly-linked list

The simplest kind of linked list is a singly-linked list (or slist for short), which has one link per node. This link points to the next node in the list, or to a null value or empty list if it is the final node.

Doubly-linked list

A more sophisticated kind of linked list is a doubly-linked list or two-way linked list. Each node has two links: one points to the previous node, or points to a null value or empty list if it is the first node; and one points to the next, or points to a null value or empty list if it is the final node.

Circularly-linked list

In a circularly-linked list, the first and final nodes are linked together. This can be done for both singly and doubly linked lists. To traverse a circular linked list, you begin at any node and follow the list in either direction until you return to the original node. Viewed another way, circularly-linked lists can be seen as having no beginning or end. This type of list is most useful for managing buffers for data ingest, and in cases where you have one object in a list and wish to iterate through all other objects in the list in no particular order.


No comments:

Post a Comment