Implement a swap between two adjacent elements

Assignment Help Computer Engineering
Reference no: EM132206498

Write a method in Java public static void swapWithNext( Node beforep ) to implement a swap between two adjacent elements by adjusting only the links (and not the data) using a single linked list. beforep is an input parameter that represents the node before the two adjacent nodes that are to be swapped.

I have already solved the problem but i do not understand how to implement a simple test class to test my program. Below is my code:

public class Problem1Swapping {

//Provided Node class to use for problem 1
private class Node {

public Object data;
public Node next;

public Node(Object data, Node next) {
this.data = data;
this.next = next;
}
}

public static void swapWithNext(Node beforeP){
Node p; //First Node to be swapped
Node afterP;//Second Node to be swapped

p = beforeP.next;
afterP = p.next;

p.next = afterP.next;
beforeP.next = afterP;
afterP.next = p;
}

}

public class Problem1SwappingTester {

public static void main(String args[]){
?????
}
}

Reference no: EM132206498

Questions Cloud

Discussion of the necessary and proper clause : In the text there is a discussion of the “Necessary and Proper” clause
Information content misuse can create moral : Information content misuse can create moral and ethical dilemmas that people are likely to face in the workplace.
Write a method that will sort an array in ascending order : Write a method that will sort an array in ascending order. Display these contents of the array before sorting and then display the contents after sorting.
Concepts of in-house counsel and outside counsel : Describe the concepts of “in-house counsel” and “outside counsel”.
Implement a swap between two adjacent elements : Implement a swap between two adjacent elements by adjusting only the links (and not the data) using a single linked list.
About quality assurance : Write a short essay (1 page or less) about Quality Assurance.
Respect for transparency of social media : Explaining its late intervention as “respect for the transparency of social media.”
Develop a coaching and development plan : In preparation for this hypothetical coaching exercise, identify one individual, staff member, or employee (from your current organization or a past setting).
To what extent do you think lack of effective : To what extent do you think lack of effective use of MIS played in the demise of the product if your example is a (b) example?

Reviews

Write a Review

Computer Engineering Questions & Answers

  Describe an algorithm for building the index

Describe an algorithm for building the index and give its big-Oh running time in terms of the total number of words.

  Difference between packet-filter firewalls and proxy filters

Explain at least two (2) differences between packet-filter firewalls and proxy filters. Provide one (1) example of a situation where you might.

  Discuss ambulance drivers needed a way to communicate

Ambulance drivers needed a way to communicate with the hospital when they were at a patient's location

  Describe the role of operating systems

MN404 - Fundamentals of Operating Systems and Programming - Describe the role of Operating Systems (OS) and its different subsystems in controlling computer

  Suppose that a vector processor has a memory system in

suppose that a vector processor has a memory system in which it takes 10 cycles to load a single 64-bit word from

  Discuss the implementation of global cybersecurity policy

addressed above and discuss the interconnectedness of these issues surrounding the implementation of global cybersecurity policy

  Find the maximum number in the array

The program provides facility to either read an array from the keyboard or from a file, at the user's choice.

  Constructor functions for your button events

constructor functions for your button events as outlined. This application simulates a vending machine that dispenses soft drinks.

  Name at least five different scans that might be performed

question 1 name at least five different scans that may be performed from the zenmap gui. document under what

  What do you think is more important for a good it

1. many people have a hard time taking a systems view when it comes to managing projects. why do you think this is the

  Determine a good asymptotic upper bound

Determine a good asymptotic upper bound on the recurrence - write a comment between each pair of lines describing what is true when the program reaches that point in the code.

  When can you use which type of loop

1) Describe the difference between a "for" and a "while" loop. When can you use which type of loop?

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd