Search

Saturday, March 15, 2014
0 comments

C function for an ADD operation

9:11 AMSaturday, March 15, 2014

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;
};


Protected by Copyscape Online Copyright Protection Software

0 comments :

Post a Comment

 
Toggle Footer
Top