C function for an ADD operation

C function for an ADD operation:


void addlq(QUEUE *front, QUEUE *rear, int item)
{
QUEUE *temp = (QUEUE*) malloc (sizeof(QUEUE));
temp-->i=item;
temp-->link=0;
if (rear= =0)
{ rear=temp; front=temp; }
else
{ rear-->link=temp; rear=temp; }
}

To implement a Linear Queue using Linked List, in C, a self-referential struct QUEUE can be used similar to Linked List implemented STACK. The user define data type struct QUEUE contain one field to store the data say int i and the other field QUEUE *link to store the address of next node.
struct QUEUE
{
int i;
QUEUE *link;
};


Comments

Popular posts from this blog

difference between structure and union in C Language

Difference between Linear search and Binary Search in c language

Difference between static and dynamic websites