What are the fundamental operations of a linked list and the main advantage of a linked list over an array?

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

What are the fundamental operations of a linked list and the main advantage of a linked list over an array?

Test program LinkedList.java, and make sure that you understand each operation in the program. (refer to linkedListApplication.java). In this code which part I will keep main.java file and which part I will keep LinkedList.java.java file. Because I will use main.java IDE. Otherwise my program doesn't run.

import java.util.*;

public class LinkedList
{
    public Node header;

    public LinkedList()
    {
        header = null;
    }

    public final Node Search(int key)
    {
        Node current = header;
        while (current != null && current.item != key)
        {
            current = current.link;
        }
        return current;
    }

    public final void Append(int newItem)
    {
        Node newNode = new Node(newItem);
        newNode.link = header;
        header = newNode;
    }

    public final Node Remove()
    {
        Node x = header;
        if (header != null)
        {
            header = header.link;
        }
        return x;
    }

    public final Node searchPrevious(int key)
    {
        if (header == null)
        {
            return header;
        }
        else
        {
            Node current = header;
            while (!(current.link == null) && (current.link.item != key))
            {
                current = current.link;
            }
            return current;
        }
    }

    public final void Insert(int newItem, int preKey)
    {
        Node current;
        Node newNode = new Node(newItem);
        current = Search(preKey);
        if (current == null)
        {
            System.out.println("there is no such preKey!");
        }
        else
        {
            newNode.link = current.link;
            current.link = newNode;
        }
    }


    public final void Delete(int key)
    {
        if (header == null) // The list is empty!
        {
            System.out.println("The list is empty!");
        }
        else
        {
            if (header.item == key) // header to be deleted.
            {
                header = header.link;
            }
            else
            {
                Node p = searchPrevious(key);
                if (p.link == null)
                {
                    System.out.println("There is no such item!");
                }
                else
                {
                    p.link = p.link.link;
                }
            }
        }
    }

    public final void ShowLinkedList()
    {
        if (header == null)
            System.out.println("The list is empty!");
        else
        {
            Node current = header;
            System.out.printf("%1$s->", current.item);
            while (!(current.link == null))
            {
                current = current.link;
                System.out.printf("%1$s->", current.item);

            }
            System.out.printf("null");
            System.out.println();
        }
    }
    public final void PrintList()
    {
        if (header == null)
        {
            System.out.println("The list is empty!");
        }
        else
        {
            Node current = header;
            System.out.println(current.item);
            while (!(current.link == null))
            {
                current = current.link;
                System.out.println(current.item);
            }
        }
    }
    
    
}

Expert Solution
Step 1

In system, A generic type of collection, which is defined in programming is known as Linked list. In order to provide very quick insertion or the deletion of a list member, the linked lists are used.

trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps

Blurred answer
Knowledge Booster
Operations of Linked List
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education