Posts

Singly Linked List Implementation

Image
Linked List is an another Abstract Data type A linked list is a data structure which contain the list of the elements The elements are stored anywhere in the memory and linked with the address. Linked list is used when the quantity of the data is unknown Data is stored in the form of node and at the run-time memory is allocate for creating a node Data is accessed using the starting pointer of the list Array versus Linked List Array suitable for         Randomly access the elements        Searching the list of particular elements        Inserting or Deleting the particular elements Linked List suitable for        Inserting/Deleting the elements        Application where sequential access is required        In situation where number of elements are unknown Types of Linked List Singly linked List Doub...

Circular Queue Implementation

Image
In the normal Queue, we can insert the data till the Queue gets full. And rear will point to the last element. Therefore, no further addition of the elements can takes place. Even the elements get deleted, the further use of the free space can not be possible. To overcome the problem of normal Queue, a new data structure is introduced called Circular Queue. In Circular Queue, the last position of the queue is connected back to first position. This structure allows the data insertion and deletion in circular manner, and allow to further use the free space of the Queue. Graphical representation of circular Queue Implementation of Circular Queue using Linked List #include #include struct node { int data; struct node *next; }*front=NULL,*rear=NULL; void Enqueue() { int n; struct node *newNode=(struct node*)malloc(sizeof(struct node)); printf("Insert the data\n"); scanf("%d",&n); newNode->data=n; if(rear==NULL) { front=newNode; rear=newNode; newNo...

Queue Implementation Using Linked List

Image
Queue implementation using linked list gives following advantages: Linked list allow dynamic allocation of memory Insertion and deletion is easy  Efficient memory utilization due to run time allocation Deletion of elements free the memory, that can further utilized by other programs Implementation of Queue First step to define the structure of the node Define two pointer called rear and front assigned with NULL Create the List of Operation in Main function Decide the condition for Queue empty or full Last inserted elements always pointed by rear #include #include struct node { int data; struct  node *next; }*front=NULL,*rear=NULL; void Inqueue() { int n; struct node *newNode=(struct node*)malloc(sizeof(struct node)); printf("Insert the data"); scanf("%d",&n); newNode->data=n; if(rear==NULL) { front=newNode; rear=newNode; newNode->next=NULL; } else { rear->next=newNode; rear=newNode; } } void Dequeue() { if(front==NULL) printf(...

Queue Implementation Using Array

Image
Queue is an another Abstract Data Type, where insertion and deletion can be performed from the one end. In Queue Data Structure, the elements are inserted and deleted in the First in First Out fashion. In Queue, the insertion is done using rear and deletion is performed through front Applications of Queue Network Programming Operating System Process Scheduling Waiting Queue Access the Shared resource (printer) Multiprograming Basic Operation of Queue EnQueue Operation (Insert the data) DeQueue Operation (Deletion of data) EnQueue Operation DeQueue Operation Queue Implementation Array Implementation Linked List Implementation Array Implementation of Queue #include #include int max=10; int a[10]; int front=-1,rear=-1; void Inqueue() { if(rear==max) printf("Queue is full"); else { int n; if(front=-1) front=0; rear=rear+1; printf("Insert the data\n"); scanf("%d",&n); a[rear]=n; printf(...

Conversion of Arithmetic Expression Using Stack

Image
Stack has various application as we have discussed in the previous post. In this post, we will see how stack is useful to convert the user input expression into a meaningful result. There are basically three types of expression: Infix expression Postfix expression Prefix expression We generally write any equation in the form of infix expression, but computer system convert this expression into Post-fix or Prefix expression for evaluating the results. Example: Infix expressions:      A+B , X*(Y+Z)                 Postfix expression:    AB+ , XYZ+*                 Prefix expression:     +AB, *X+YZ The transformation  of any Infix expression into Postfix expression is performed based on the precedence of the operators.  The higher precedence operator evaluation is performed first, later the others operators.   If two operato...

Stack Implementation Using Linked-List

Image
The stack implementation using the linked list. Advantages: Always takes constant time to push and pop the elements Can grow to infinite size Disadvantages: More time take to find the k th element in the list Require more memory storage for each data element Implementation of Stack using the Linked List First step is to define the node structure Variable name called TOP for indexing  Check the condition for Empty and Full of the list Make a function to display the List elements Make a function for PUSH and POP operation #include #include struct node { int data; struct node *next; }*top=NULL; void push() { int n; struct node *newNode; newNode=(struct node*)malloc(sizeof(struct node)); printf("enter the data\n"); scanf("%d",&n); newNode->data=n; if (top==NULL) newNode->next=NULL; else newNode->next=top; top=newNode; printf("insert is sucessfull"); } void pop() { if (top==NULL) printf(...