Write a method called hasTwoConsecutive that returns whether or not a list of integers has two adjacent numbers that are consecutive integers ( true if such a pair exists and false otherwise). For example, if a variable list stores the values [1, 18, 2, 7, 8, 39, 18, 40] , then the call list.hasTwoConsecutive() should return true because the list contains the adjacent numbers ( 7, 8 ), which are a pair of consecutive numbers.
Add the above method to the LinkedIntList class from this chapter.
Implementation of hasTwoConsecutive method:
public boolean hasTwoConsecutive()
{
if(front == null)
return false;
ListNode current = front;
while(current.next != null)
{
if(current.data == current.next.data - 1)
return true;
current = current.next;
}
return false;
}