Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

java INode next 1) (15 pts) myList and mylist2 point to two different singly linked lists. Create a swap function that exchanges the data elements

image text in transcribedjava

INode next 1) (15 pts) myList and mylist2 point to two different singly linked lists. Create a swap function that exchanges the data elements between the two lists. The nodes are identified by number and are passed as parameters. For example, to exchange node 2 from myList with node 3 from myListz, cal swap (myusti 2. myust23 CAUTION: Keep in mind that you are not exchanging the nodes, only the data values Here is an Example: myListi: 10 20 myList2:50 80 90 100 3 0 70 (myList is the head of the first list) (myList2 is the head of the second list) Node 1 Node 4 Node number myusu myusa 10 Node 2 20 80 Node 3 90 100 30 50 70 Example: Given the following call: swap(myList1, 2, myList2, 3); The contents of myListland myList2 after the function call would be as such myList: 10 100 90 30 myList2: 50 80 20 70 Precondition: The items swapped will be valid. In other words, they will not be outside the list. Th lists will not be empty. They will contain nodes. inction header swap(Node myList 1, int a, Node myList2, int b){ urt here This is the last part you should do de to get the location of node in list1! // Code to Swap the data. You are swapping two ints. the second part you should do get to the location of node in list2 INode next 1) (15 pts) myList and mylist2 point to two different singly linked lists. Create a swap function that exchanges the data elements between the two lists. The nodes are identified by number and are passed as parameters. For example, to exchange node 2 from myList with node 3 from myListz, cal swap (myusti 2. myust23 CAUTION: Keep in mind that you are not exchanging the nodes, only the data values Here is an Example: myListi: 10 20 myList2:50 80 90 100 3 0 70 (myList is the head of the first list) (myList2 is the head of the second list) Node 1 Node 4 Node number myusu myusa 10 Node 2 20 80 Node 3 90 100 30 50 70 Example: Given the following call: swap(myList1, 2, myList2, 3); The contents of myListland myList2 after the function call would be as such myList: 10 100 90 30 myList2: 50 80 20 70 Precondition: The items swapped will be valid. In other words, they will not be outside the list. Th lists will not be empty. They will contain nodes. inction header swap(Node myList 1, int a, Node myList2, int b){ urt here This is the last part you should do de to get the location of node in list1! // Code to Swap the data. You are swapping two ints. the second part you should do get to the location of node in list2

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

Objects And Databases International Symposium Sophia Antipolis France June 13 2000 Revised Papers Lncs 1944

Authors: Klaus R. Dittrich ,Giovanna Guerrini ,Isabella Merlo ,Marta Oliva ,M. Elena Rodriguez

2001st Edition

3540416641, 978-3540416647

More Books

Students also viewed these Databases questions