- #1
dan2222
- 6
- 0
- Homework Statement
- 1. A method gets a linked list of integers: 'lst', a reference position - 'p' to one of the values in the list, and a positive integer number.
The method updates the list in the following way - deletes several values from place p.
2. A method gets a list of integers and looks for the longest sequence arranged in ascending order) Suppose there is one maximum sequence.
The method should delete the maximum sequence from the given list and return the list after the change. Suppose as a sequence that actually rises is considered larger than 1.
Example 1:
lst ={ 3, 1, 2, 3, 2, -3, -1, 2, 4, 7,2 }
The maximum sequence is { -3, -1, 2, 4, 7}
The action will return lst = {3, 1, 2, 3, 2, 2 }
Example 2:
lst ={ 1, 0, 1, 6, 12, 23, 90 }
The maximum sequence is: {0, 1, 6, 12, 23, 90}
The action will return: lst = {1 }
I succeded to do the first method, but I could not do the second one.
The first method:
Thanks for those who can help!
The first method:
Code:
public static Node<int> Delete(Node<int> lst, int num)
{
Node<int> p = lst.GetNext();
for (int i = 1; i < num; i++)
{
p = p.GetNext();
}
p.SetNext(p.GetNext());
return p;
}
Thanks for those who can help!
Last edited by a moderator: