Compare commits
12
Commits
28364c2f27
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
2efbc6e1cb | ||
|
|
654eae8007 | ||
|
|
3ccfb3e420 | ||
|
|
08aa0d19e8 | ||
|
|
791b774d2f | ||
|
|
b63c9f1ccb | ||
|
|
d1e0062ae7 | ||
|
|
38837667c2 | ||
|
|
6c9f757c62 | ||
|
|
280758e7b5 | ||
|
|
dc5257ce84 | ||
|
|
7a123d5f21 |
Executable
BIN
Binary file not shown.
@@ -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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Node *search(int value)
|
||||||
|
{
|
||||||
|
Node *temp = head;
|
||||||
|
|
||||||
|
while (temp != NULL)
|
||||||
|
{
|
||||||
|
if (temp->data == value)
|
||||||
|
{
|
||||||
|
return temp;
|
||||||
|
}
|
||||||
|
|
||||||
|
temp = temp->next;
|
||||||
|
}
|
||||||
|
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
int count()
|
||||||
|
{
|
||||||
|
int count = 0;
|
||||||
|
Node *temp = head;
|
||||||
|
|
||||||
|
while (temp != NULL)
|
||||||
|
{
|
||||||
|
count++;
|
||||||
|
temp = temp->next;
|
||||||
|
}
|
||||||
|
|
||||||
|
return count;
|
||||||
|
}
|
||||||
@@ -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();
|
||||||
|
Node *search(int value);
|
||||||
|
int count();
|
||||||
|
|
||||||
|
#endif
|
||||||
@@ -0,0 +1,33 @@
|
|||||||
|
#include <stdio.h>
|
||||||
|
#include "linkedlist.h"
|
||||||
|
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
insert(10);
|
||||||
|
insert(20);
|
||||||
|
insert(30);
|
||||||
|
printf("Linked List: ");
|
||||||
|
|
||||||
|
display();
|
||||||
|
|
||||||
|
Node *result = search(20);
|
||||||
|
if (result != NULL)
|
||||||
|
{
|
||||||
|
printf("\n the Element found: %d\n", result->data);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
printf("\n the Element not found\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
printf("Total nodes = %d\n", count());
|
||||||
|
|
||||||
|
printf("Count operation completes.\n");
|
||||||
|
|
||||||
|
printf("\nThis is Main Branch\n");
|
||||||
|
|
||||||
|
printf("\nThis is Feature Branch\n");
|
||||||
|
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user