Sunday, 6 July 2014

Displaying the linked list elements

/*
Function to display the student with highest CGPA in a linked list containing student data.
 Use the following node structure for your linked list.
*/
struct node{
int stNo;
float CGPA;
struct node *next;
};

typedef struct node *NODEPTR;
void DisplayMax(NODEPTR plist)
{
NODEPTR p;
float maxCGPA=-1.0;
int maxstNo;
p = plist;
/*current node*/
if(p == NULL){
printf(“no node/data is available in the list\n”);
return;
}
do{
if(p->CGPA > maxCGPA){
maxCGPA = p->CGPA;
maxstNo = p->stNo;
}
p = p->next;
} while(p!= NULL);
printf(“The student number with max CGPA: %d\n”, maxstNo);
printf(“The student’s CGPA: %d\n”, maxCGPA);
}

No comments:

Post a Comment