LinkedList

Linked list is a data structure used for storing collection of data.Linked list have following properties:

  • Successive element are connected with pointers.
  • Last element point to null.
  • Can grow and shrink in size during program execution
  • Can be made just as long as required.
  • It does not waste memory space

Image result for linkedlist

Linked list ADT

1.Main Linked list operation

  • Insert:insert an element into the list
  • Delete:remove and return the specified position

2. Auxiliary Linked list operation

  •  Delete List:remove all element from the list
  • Count:return the number of element of the list
  • Find n position node from the end of list

Representation of Linked list in java

class LinkedList{

Node head;

class Node{

int data;

Node next;

Node(int d){

data=d;

}

}

}

 

Searching in a single linked list with c

/*searching in linked list
@author Mitra N Mishra
*/

#include<stdio.h>
struct node
{
int value;
struct node *link;
};

void main()
{
int n;
printf(“Enter value to search\n”);
scanf(“%d”,&n);

struct node *p,n1,n2,n3,n4,n5;//for searching purpose we create a structure pointer p.and also five nodes.
struct node *start=&n1;//In linked list we only access or operation perform by the help pointer start.
n1.value=100;
n1.link=&n2;
n2.value=200;
n2.link=&n3;
n3.value=300;
n3.link=&n4;
n4.value=400;
n4.link=&n5;
n5.value=500;
n5.link=NULL;
p=start;
int pos=1;
while(p!=NULL)
{
if(p->value==n){
printf(“Item %d found at position %d\n”, n,pos);
return;
}

p=p->link;
pos++;
}
printf(“Item not found \n”);
}

Traversing a single linked list with c

#include<stdio.h>
//Basic decleration of linked list with the help of referential structure A refential structure which use structure as a references.
//linked list declerations
struct node
{
int value;
struct node *link;

};
//Main method operation performed
void main()
{
struct node *p,n1,n2,n3,n4,n5;//for traversing purpose we create a structure pointer p.and also five nodes.
struct node *start=&n1;//In linkedin we only access or operation perform by the help pointer start.

n1.value=100;
n1.link=&n2;
n2.value=200;
n2.link=&n3;
n3.value=300;
n3.link=&n4;
n4.value=400;
n4.link=&n5;
n5.value=500;
n5.link=NULL;

if(start==NULL)
{
printf(“Linked List is Empty\n”);
return;
}
p=start;
printf(“The list is\n”);
while(p!=NULL)
{
printf(“%d”, p->value);
p=p->link;
}
printf(“\n\n”);
}