















Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
An overview of various data structures and algorithms in the context of java programming. It covers the fundamental concepts of lists, including array-based lists, singly linked lists, circular lists, and doubly linked lists. The characteristics, implementation, and operations of these different list data structures. It also introduces the linkedlist and arraylist classes from the java.util package, which provide built-in list functionality in java. The document aims to equip readers with a solid understanding of list data structures and their practical applications in software development. It includes detailed explanations, code examples, and illustrations to facilitate learning and understanding of these important data structures and algorithms.
Typology: Study notes
1 / 23
This page cannot be seen from the preview
Don't miss anything!
















2
4
situations. However, it has some important
limitations:
situations.
DataNode
Employee info;
DataNode next;
trees Linked lists
Employee
String name;
int age;
DataNode
Employee info;
DataNode left;
DataNode right;
Self-Referential Structures
7
A singly linked list is a list whose node includes two
datafields: info and next. The info field is used to store
information, and this is important to the user. The next
field is used to link to its successor in this sequence
The following image depicts a simple integer linked list.
head (^) tail
Singly Linked List
8
class Node
{int info;
Node next;
Node() {}
Node(int x, Node p)
{info=x;next=p;
void add(int x)
{ if(isEmpty())
head=tail=new Node(x,null);
else
{Node q =new Node(x,null);
tail.next=q; tail=q;
void traverse()
{Node p=head;
while(p!=null)
{System.out.print(" " + p.info);
p=p.next;
System.out.println();
Node search(int x) {...}
void dele(int x) {...}
class MyList
{Node head,tail;
MyList()
{head=tail=null;}
boolean isEmpty()
{return(head==null);
void clear()
{head=tail=null;
10
Inserting a new node at the end of a list
Inserting a new node at the end of a Singly Linked List
Singly Linked Lists - 3
Deleting a node from the beginning of a list
11
Deleting a node from the beginning of a Singly Linked List
13
list is finite and each node has a successor
Circular SIngly Linked List
Circular Lists - 2
Inserting nodes
14
Inserting nodes at the front of a circular singly linked list (a) and at its end (b)
class Node
{int info;
Node prev,next;
Node() {}
Node(int x, Node p, Node q)
{info=x;prev=p; next=q;
class MyList
{Node head,tail;
MyList() {head=tail=null;}
boolean isEmpty()
{return(head==null); }
void clear() {head=tail=null;}
void add(int x)
{if(isEmpty())
head=tail=new Node(x,null,null);
else
{Node q =new Node(x,tail,null);
tail.next=q;
tail=q;
Doubly Linked List
Doubly Linked Lists - 2
Adding a new node at the end
17
Adding new node at the end of Doubly Linked List
boolean add( E o) Appends the specified element to the end of this list.
void addFirst( E o) Inserts the given element at the beginning of this list.
void addLast( E o) Appends the given element to the end of this list.
void clear() Removes all of the elements from this list.
E get(int index) Returns the element at the specified position in this list.
E getFirst() Returns the first element in this list.
E getLast() Returns the last element in this list.
E remove(int index) Removes the element at the specified position in
this list.
E removeFirst() Removes and returns the first element from this list.
E removeLast() Removes and returns the last element from this list.
int size() Returns the number of elements in this list.
Object[] toArray() Returns an array containing all of the elements in this list in
the correct order.
import java.util.*;
class Node
{ String name;
int age;
Node() {}
Node(String name1, int age1)
{ name=name1; age=age1;
void set(String name1, int age1)
{ name=name1; age=age1;
public String toString()
{ String s = name+" "+age;
return(s);
class Main
public static void main(String [] args)
LinkedList t = new LinkedList();
Node x; int n,i;
x = new Node("A01",25); t.add(x);
x = new Node("A02",23); t.add(x);
x = new Node("A03",21); t.add(x);
for(i=0;i<t.size();i++)
System.out.println(t.get(i));