SAVITIBAI PHULE UNIVERSITY OF PUNE
S. Y. B.Sc. (Computer Science) Semester III
Practical Examination
SUBJECT: CS-233 Practical course based on CS231
/* Implement a list library (singlylist.h) for a singly linked list. Create a linked list, reverse it and display reversed linked list.*/
/// File name : "singlylist.c"
#include"singlylist.h"
void CreateList()
{
struct node *NewNode = NULL;
NewNode = (struct node *) malloc(sizeof(struct node));
if (NewNode != NULL)
{
NewNode->Next = NULL;
printf("Enter the data value: ");
scanf("%d", &(NewNode->data));
if (Head == NULL)
{
Head = Last = NewNode;
}
else
{
Last->Next = NewNode;
Last = NewNode;
}
}
}
void Display()
{
struct node *temp = Head;
printf("\n\nThe given Linked List is : ");
while (temp != NULL)
{
if (temp->Next != NULL)
printf("%d ->", temp->data);
else
printf("%d", temp->data);
temp = temp->Next;
}
}
struct Node* ReverseLinkedList()
{
struct Node *current = NULL, *reverse = NULL, *temp = NULL;
current = Head;
while(current != NULL)
{
temp = reverse;
reverse = current;
current = current->Next;
reverse->Next = temp;
}
Head = reverse;
}
No comments:
Post a Comment