Page 195 - DCAP201_FUNDAMENTALS_OF_DATA_STRUCTURES
P. 195
Fundamentals of Data Structures
Notes enqueue(&front,&rear,element);/
/Function call
break;
case 2:
element = dequeue(&front,&rear);
printf("The deleted element is :
%d",element);
break;
case 3:
display(front);
break;
default:
printf("Enter the right choice : ");
}//switch
}while(choice !=4);
}//main
void enqueue(node **front, node **rear, int element)
{
node * temp,*current;
current = (node*)malloc(sizeof(node*));
current->x = element;
current->next = NULL;
if(*front == NULL)
{
*front = *rear = current;
}
else
{
temp = *rear; //use pointer to structure to access
structure members
temp->next=current;
temp=temp->next;
*rear=temp;
}
} //enqueue
int dequeue(node **front,node **rear)
{
node *temp;
int element;
if(*front == *rear) //Deleting last node
{
Contd...
188 LOVELY PROFESSIONAL UNIVERSITY