Write a member method getPosition(int entry) which returns the position of the entry is in the linked list. If the entry is not in the list , return -1.
Note: Use C++ language
// Considering the linked list contains unique elements and positioning starts from 1
Node* head; // contains the head of the linked list declared global here
int getPosition(int entry)
{
Node* temp = head;
int count = 1;
while(temp!=NULL && temp->data != entry)
{
count++;
temp = temp->next;
}
if(temp == NULL) // entry is not present in the linked list
{
return -1;
}
return count;
}
Hope this code helps you. Please give an upvote if it does.
Write a member method getPosition(int entry) which returns the position of the entry is in the...
a) Write a member method remove() which randomly generate a position and deletes the node at that position from the linked list. Note: Use C++ language and there is code for the linked list.
Fix Java Code Question: Coding AList Get Position Write a method for the AList class that returns the first position of a given object in the list with the method header below. public int getPosition(T anObject) Answer: public int getPosition(T anObject) { int position = 0; for (int i = 0; i < length; i++) if (list[i].equals(anObject)) { position = i + 1; } return position; }
In Java, write a class Grade with following member variables and method: int midtermExam, int finalExam: represent the scores of midterm and final exams respectively. The maximum score for each exam is 100. double getOverallScore(): returns the overall score calculated as follows: 40% midterm and 60% final. Write another class Grade180 that is a subclass of Grade and has the following member variables and method: int midtermExam, int finalExam: inherited from Grade super class. int hw1, int hw2, int project1,...
Q1)(20p)Write a static member function called removeLongestRepeatingSegment that takes a String argument. The method will return a new String by removing the logest segment that contains consequtively repeating characters. public static void main(String []args){ String s=”1111222223333311111111444455552222”; String res= removeLongestRepeatingSegment(s); will return “11112222233333444455552222” } public static String removeLongestRepeatingSegment(String s){ --------------- Q2)15p)Given a list of objects stored (in ascending order) in a sorted linked list, implement member method which performs search as efficiently as possible for an object based on a key....
Write a recursive method contains(int target, LLNode<Integer> list) that returns true if list contains target and false otherwise. For our example list contains(15, values) would return true while contains(10, values) would return false. (JAVA language)
Write an efficient java private int countodds (node t) method that returns the number of odd integers in a singly linked list headed by node t. ( Assume class node is defined as: private class node {int data; node rlink;}
Simple singly-linked list question: write an iterative function position(p, target) that returns position (1, 2, 3, or .......) of the target in the list to which p points. If target is not on the list the function returns -1. please write the function in C++ thanks
Write the pseudocode for a non-member method“dequeue” which is utilizing a linked list. The list node has 2 attributes: data and next. The method would take a “front” and “rear” reference and will return a “character” (the data element from the de-queued node). **Special note: DO NOT ASSUME THE EXISTENCE OF ANY OTHER METHODS (i.e. don’t use any other methods). Use basic definitions and standard naming conventions for the stack and queue data structures, figure out the requirements, inputs &...
Write a cell method that takes a single double as an argument and returns an int. The int should be the next highest whole integer (eg 3.14 would return 4). Use math not built-in Java methods mins) Write a method that takes a string as an argument. It your string is more than 10 letters or less than 1 letter return "Bad number". Otherwise, return the telephone number equivalent of the input. Your return can be of type String Eg...
Write a ceil method that takes a single double as an argument and returns an int. The int should be the next highest whole integer (eg 3.14 would return 4). Use math, not built-in Java methods (est. 20 mins) Write a method that takes a string as an argument. If your string is more than 10 letters or less than 1 letter return "Bad number." Otherwise, return the telephone number equivalent of the input. Your return can be of type...