Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Other solutions here for these questions were either incorrect or incomplete. Thanks! Implement the search(int k), insert(int x), delete() function in LinkedList.java as discussed in

Other solutions here for these questions were either incorrect or incomplete. Thanks!

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

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()); } }

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

Step: 3

blur-text-image

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

Oracle Database Upgrade Migration And Transformation Tips And Techniques

Authors: Edward Whalen ,Jim Czuprynski

1st Edition

0071846050, 978-0071846059

More Books

Students also viewed these Databases questions