0% found this document useful (0 votes)
36 views

Singly Link List

This document discusses linked lists and their implementation and use. It describes linked lists as a series of connected nodes, where each node contains a data element and a pointer to the next node. The document outlines common linked list operations like insertion, deletion, finding nodes, and traversal. It provides examples of implementing Node and List classes in code. Finally, it discusses applications of linked lists like databases, word processors, operating systems, and web browsers.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
36 views

Singly Link List

This document discusses linked lists and their implementation and use. It describes linked lists as a series of connected nodes, where each node contains a data element and a pointer to the next node. The document outlines common linked list operations like insertion, deletion, finding nodes, and traversal. It provides examples of implementing Node and List classes in code. Finally, it discusses applications of linked lists like databases, word processors, operating systems, and web browsers.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 12

CSE 247

Data Structures
Linked list

outline
Linked lists
Motivation
Abstract data type (ADT)

Basic operations of linked lists


Insert, find, delete, traversal, etc.

Quratulain Rajput

Motivation
The organization of data is very important because the

organization can effect the performance of operations. Where


operations on list could be:
Insertion
Deletion
Find so on

There are two possible data structure to organize the data as

list in memory.
Array
Linked list

Quratulain Rajput

Linked Lists
A

Null

Head

A linked list is a series of connected nodes


Each node contains at least

node

A piece of data (any type)


Pointer to the next node in the list

Head: pointer to the first node


The Null indicates end of list

A
data

pointer

Linked List

Actual picture in memory:


current

head

1051

1052

1063

1053

1063

1054

1055

1051

1056

current

1057

1058

1060

1059

head

1060

1061

null

1062

1054

1063

1064

1057

1065

Implementation of Node class


class Node{
int data;
Node next;
Node () { // no argument constructor
data=0;
next=null;
}
Node (intV) { // one argument constructor
data=V;
next=null;
} }
6

Quratulain Rajput

Implementation of List class


class LIST{
Node Head;
LIST (){
Head=null;
}
// list operations (insertion, deletion, )
}

Quratulain Rajput

A Singly Linked List


Operations of List
IsEmpty: determine whether or not the list is empty
InsertNode: insert a new node in the end of list
FindNode: find a node with a given value

DeleteNode: delete a node with a given value


DisplayList: print all the nodes in the list
Clear: delete all node from list / make it an empty list
InsertInOrder: Insertion according to sorted order.

Insert operation in linked list


public void INSERT(int value){
Node NewNode=new Node(value);
Node Temp=null, Prev=null;
if(Head==null){
Head=NewNode;
}else{ Temp=Head;
while(Temp!=null){
Prev=Temp;
Temp=Temp.next;
}
Prev.next=NewNode;
} }
9

Quratulain Rajput

Display list items


public void DisplayList(){
Node Temp=Head;
int i=0;
while(Temp!=null){
i++;
System.out.println("Item "+i+ Temp.data);
Temp=Temp.next;
}
}
10

Quratulain Rajput

Application of Singly linked list


Operations in databases
In word processor, del
Operating system cache scheduling algorithm (LRU)
In browser BACK button. (List of urls)

11

Analysis of Singly linked list


Insertion and deletion at current reference is one step

operation.
Search entire list when:
To find an item that not stored in a list or stored at the end.

Moving back from current position is requires to traverse a

list again from beginning. This problem is resolved by doubly


linked list.

12

You might also like