Data Structures In C Programming Language

Data Structure:- The data structure can be defined as the collection of elements and all the possible operations which are required for those set of elements. The operations includes inserting, deleting, searching and printing an element. It is the way of representing logical relationship between individual data elements.
Data structure is the representation of the logical relationship existing between individual elements of data.
A data structure is a way of organizing all data items that considers not only the elements stored but also their relationship to each other.
Read Also:
  1. Preprocessor Directives
  2. Linked List
  3. Conditions Statements
Data structure is define as a mathematical or logical model of particular organization of data items. Data structure mainly specifies the following four things:
  • Organization of data 
  • Accessing methods
  • Degree of associativity
  • Processing alternatives for information
Type Of Data Structure:- The data structures are divided into the following two categories:
1. Linear data structure: A linear data structure is a data structure whose elements form a sequence, and every element in the structure has a unique predecessor and unique successor.
Examples of linear data structure are arrays, linked lists, stacks and queues. 
2. Non-linear data structure: It is a data structure whose elements do not form a sequence. There is no unique predecessor or unique successor.
Examples of non-linear data structures are trees and graphs.
Types Of Liner Data Structure:- There are many types of liner Data Structure, which listed below:
  1. Array
  2. Linked List
  3. Stack
  4. Queue
1. Array:- Click Here To Know.
2. Linked List:- Click Here To Know
3. Stack:- A stack is a ordered collection of data elements. The elements already stored may be deleted or new elements may be inserted at one end, called the top of the stack. It is a data structure in which only the top element can be accessed.
Unlike array, the definition of the stack provides for insertion and deletion of items, so that stack is a dynamic, constantly changing object. Removing the data element from a stack is called Poping the stack or pop operation and storing an element on the stack is called pushing it onto the stack or push operation. The information stored on the stack much like stacking plates. Using this analogyo stacking plates it is easy to illustrate the stach operation.
It is an ordered list in all insertions and deletions are made at one which end, called shown in the figure, if we have stack of elements 10, 20, 30, 40, 50, 60 then 10 will be the bottommost element and 60 will be the topmost element in the stack.
Let us see the operations which can be carried out on the stack.
  • To create a stack. 
  • To insert an element onto the stack. 
  • To delete an element from the stack. 
  • To check which element is at the top of the stack. 
  • To check whether a stack is empty or not. 
The create function creates a stack in the memory. The way we create a stack and carry out all other operations depend on how the stack is implemented. The insert function inserts a new element at the top of the stack, while the delete function removes the element which is at the top of the stack. Many times we need to test for the topmost element of the stack and to test whether the stack is empty or Honempty before we make subsequent operations. The function which tests for the cmptiness of the stack, say, 'stempty' is a boolean function which returns true if the ack is empty and false otherwise. Similarly, a function, say, 'stfull' is a boolean function which tests whether the stack is full or not. It returns true if it is full and false otherwise.
Declaration: A stack in C can be declared as a structure containing two objects: an array to hold the elements of the stack, and an integer to indicate the position of the current top of stack within the array.

Here, we assume that the elements of the stack st contained in the array st.items are integers and that the stack will at no time contain more than STACKSIZE, i.e. 10 integers.
Queues:- In the previous section we have seen the stack data structure, in which the elements are inserted and deleted from one end only. We are calling such a data structure as LIFO. So in stack, the element that has entered at the last can come out first and the element that has entered first has to come out last. Let us now get introduced with another data structure known as Queue. The Queue is a data structure that allows using two ends of it. This means that from one end of the queue we can insert the elements and from another end of the queue we can delete the element. The queue can be formally defined as ordered collection of elements that has two ends named as front and rear. From the front end one can delete the elements and from the rear end one can insert the element.
For Example: The typical example can be a queue of people who are waiting for a city bus at the bus stop.
Any new person is joining at one end of the queue, you can call it as the rear end. When the bus arrives, the person at the other end first enters in the bus. You can call it as the front end of the queue.
As we have seen, queue is nothing but the collection of items. Both the ends of the queue are having their own functionality. The Queue is also called FIFO i.e. a First In First Out data structure.
All the elements in the queue are stored sequentially.
The various operations on the queue are:
1. Queue Overflow.
2. Insertion of the element into the queue.
3. Queue Underflow.
4. Deletion of the element from the queue.
5. Display of the queue. 

Post a comment