Compare commits

..
3 Commits
Author SHA1 Message Date
SF 280758e7b5 Added count feature 2026-07-30 06:49:33 +00:00
SF dc5257ce84 Added search feature 2026-07-30 06:42:38 +00:00
SF 7a123d5f21 Created basic linked list 2026-07-30 06:31:27 +00:00
4 changed files with 97 additions and 0 deletions
Executable
BIN
View File
Binary file not shown.
+57
View File
@@ -0,0 +1,57 @@
#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;
}
+17
View File
@@ -0,0 +1,17 @@
#ifndef LINKEDLIST_H
#define LINKEDLIST_H
typedef struct Node
{
int data;
struct Node *next;
} Node;
void insert(int data);
void display();
int search(int value);
int count();
#endif
+23
View File
@@ -0,0 +1,23 @@
#include <stdio.h>
#include "linkedlist.h"
int main()
{
insert(10);
insert(20);
insert(30);
display();
if (search(20))
{
printf("\nElement found\n");
}
else
{
printf("\nElement not found\n");
}
printf("Total nodes = %d\n", count());
return 0;
}