Compare commits
3
Commits
main
..
c0a432b2e7
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c0a432b2e7 | ||
|
|
4d9c36b471 | ||
|
|
9f333aa21c |
BIN
Binary file not shown.
+21
-20
@@ -1,9 +1,11 @@
|
|||||||
#include <stdio.h>
|
#include<stdio.h>
|
||||||
#include <stdlib.h>
|
#include<stdlib.h>
|
||||||
#include "linkedlist.h"
|
#include "linkedlist.h"
|
||||||
|
|
||||||
|
|
||||||
Node *head = NULL;
|
Node *head = NULL;
|
||||||
|
|
||||||
|
|
||||||
void insert(int data)
|
void insert(int data)
|
||||||
{
|
{
|
||||||
Node *newNode = malloc(sizeof(Node));
|
Node *newNode = malloc(sizeof(Node));
|
||||||
@@ -14,40 +16,39 @@ void insert(int data)
|
|||||||
head = newNode;
|
head = newNode;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void display()
|
void display()
|
||||||
|
{
|
||||||
|
Node *temp=head;
|
||||||
|
|
||||||
|
while(temp!=NULL)
|
||||||
|
{
|
||||||
|
printf("%d ",temp->data);
|
||||||
|
temp=temp->next;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int search(int value)
|
||||||
{
|
{
|
||||||
Node *temp = head;
|
Node *temp = head;
|
||||||
|
|
||||||
while(temp != NULL)
|
while(temp != NULL)
|
||||||
{
|
{
|
||||||
printf("%d ", temp->data);
|
if(temp->data == value)
|
||||||
temp = temp->next;
|
return 1;
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Node *search(int value)
|
|
||||||
{
|
|
||||||
Node *temp = head;
|
|
||||||
|
|
||||||
while (temp != NULL)
|
|
||||||
{
|
|
||||||
if (temp->data == value)
|
|
||||||
{
|
|
||||||
return temp;
|
|
||||||
}
|
|
||||||
|
|
||||||
temp = temp->next;
|
temp = temp->next;
|
||||||
}
|
}
|
||||||
|
return 0;
|
||||||
return NULL;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int count()
|
int count()
|
||||||
{
|
{
|
||||||
int count = 0;
|
int count = 0;
|
||||||
|
|
||||||
Node *temp = head;
|
Node *temp = head;
|
||||||
|
|
||||||
while (temp != NULL)
|
while(temp != NULL)
|
||||||
{
|
{
|
||||||
count++;
|
count++;
|
||||||
temp = temp->next;
|
temp = temp->next;
|
||||||
|
|||||||
+3
-3
@@ -1,4 +1,3 @@
|
|||||||
|
|
||||||
#ifndef LINKEDLIST_H
|
#ifndef LINKEDLIST_H
|
||||||
#define LINKEDLIST_H
|
#define LINKEDLIST_H
|
||||||
|
|
||||||
@@ -7,11 +6,12 @@ typedef struct Node
|
|||||||
int data;
|
int data;
|
||||||
struct Node *next;
|
struct Node *next;
|
||||||
|
|
||||||
} Node;
|
}Node;
|
||||||
|
|
||||||
|
|
||||||
void insert(int data);
|
void insert(int data);
|
||||||
void display();
|
void display();
|
||||||
Node *search(int value);
|
int search(int value);
|
||||||
int count();
|
int count();
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -1,33 +1,29 @@
|
|||||||
#include <stdio.h>
|
#include<stdio.h>
|
||||||
#include "linkedlist.h"
|
#include "linkedlist.h"
|
||||||
|
|
||||||
|
|
||||||
int main()
|
int main()
|
||||||
{
|
{
|
||||||
|
|
||||||
insert(10);
|
insert(10);
|
||||||
insert(20);
|
insert(20);
|
||||||
insert(30);
|
insert(30);
|
||||||
printf("Linked List: ");
|
|
||||||
|
|
||||||
display();
|
display();
|
||||||
|
|
||||||
Node *result = search(20);
|
int result = search(20);
|
||||||
if (result != NULL)
|
|
||||||
|
if(result)
|
||||||
{
|
{
|
||||||
printf("\n the Element found: %d\n", result->data);
|
printf("\nElement found");
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
printf("\n the Element not found\n");
|
printf("\nElement not found");
|
||||||
}
|
}
|
||||||
|
printf("\nTotal nodes = %d", count());
|
||||||
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;
|
return 0;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user