Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Implement the search(int k), insert(int x), delete() function in LinkedList.java public class LinkedList { public ListNode head; public LinkedList () { head = null; }

Implement the search(int k), insert(int x), delete() function in LinkedList.java

public class LinkedList { public ListNode head; public LinkedList () { head = null; } /* * Implement the LIST-SEARCH(L, k) function */ public ListNode search (int k) { } /* * Implement the LIST-INSERT(L, x) function * Note that x is a integer value, not a ListNode */ public void insert (int x) { } /* * Implement the LIST-DELETE(L, x) function */ public void delete (ListNode x) { } /* * Convert a LinkedList to a string in the format of [#elements] */ public String toString () { String str; ListNode n; str = "["; n = this.head; while (n != null) { str += n.key + ","; n = n.next; } str += "]"; return str; } /** * @param args */ public static void main(String[] args) { // TODO Auto-generated method stub LinkedList l; l = new LinkedList(); for (int i = 0; i < 5; i++) l.insert(i); System.out.println(l.toString()); for (int i = 0; i < 2; i++) l.delete(l.head.next); System.out.println(l.toString()); }

}

public class ListNode { public int key; public ListNode prev; public ListNode next; public ListNode () { prev = next = null; } public ListNode (int _key) { key = _key; prev = next = null; } }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

DNA Databases

Authors: Stefan Kiesbye

1st Edition

0737758910, 978-0737758917

More Books

Students also viewed these Databases questions