58 lines
740 B
C
58 lines
740 B
C
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include "linkedlist.h"
|
|
|
|
Node *head = NULL;
|
|
|
|
void insert(int data)
|
|
{
|
|
Node *newNode = malloc(sizeof(Node));
|
|
|
|
newNode->data = data;
|
|
newNode->next = head;
|
|
|
|
head = newNode;
|
|
}
|
|
|
|
void display()
|
|
{
|
|
Node *temp = head;
|
|
|
|
while(temp != NULL)
|
|
{
|
|
printf("%d ", temp->data);
|
|
temp = temp->next;
|
|
}
|
|
}
|
|
|
|
int search(int value)
|
|
{
|
|
Node *temp = head;
|
|
|
|
while (temp != NULL)
|
|
{
|
|
if (temp->data == value)
|
|
{
|
|
return 1;
|
|
}
|
|
|
|
temp = temp->next;
|
|
}
|
|
|
|
return 0;
|
|
}
|
|
|
|
int count()
|
|
{
|
|
int count = 0;
|
|
Node *temp = head;
|
|
|
|
while (temp != NULL)
|
|
{
|
|
count++;
|
|
temp = temp->next;
|
|
}
|
|
|
|
return count;
|
|
}
|