Computer Science Help C# or Java

Click For Summary
The discussion centers on a user's challenge in implementing a second method in C# after successfully completing the first method for deleting a node from a linked list. The user shares their code for the deletion method, which navigates through the list to remove a specified node. They seek assistance in counting the length of a sequence and tracking the longest sequence found. The forum emphasizes the importance of showing attempts to encourage collaborative problem-solving. Overall, the user is looking for guidance on advancing their coding skills in C#.
dan2222
Messages
6
Reaction score
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:
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:
Physics news on Phys.org
Per forum rules, you need to show an attempt.
Start by finding a way to count the length of a sequence.
Then consider how you might keep track of the longest sequence found so far.
 
Thread 'Chain falling out of a horizontal tube onto a table'
My attempt: Initial total M.E = PE of hanging part + PE of part of chain in the tube. I've considered the table as to be at zero of PE. PE of hanging part = ##\frac{1}{2} \frac{m}{l}gh^{2}##. PE of part in the tube = ##\frac{m}{l}(l - h)gh##. Final ME = ##\frac{1}{2}\frac{m}{l}gh^{2}## + ##\frac{1}{2}\frac{m}{l}hv^{2}##. Since Initial ME = Final ME. Therefore, ##\frac{1}{2}\frac{m}{l}hv^{2}## = ##\frac{m}{l}(l-h)gh##. Solving this gives: ## v = \sqrt{2g(l-h)}##. But the answer in the book...

Similar threads

  • · Replies 3 ·
Replies
3
Views
2K
  • · Replies 5 ·
Replies
5
Views
3K
  • · Replies 3 ·
Replies
3
Views
1K
  • · Replies 10 ·
Replies
10
Views
2K
Replies
8
Views
2K
  • · Replies 3 ·
Replies
3
Views
2K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 3 ·
Replies
3
Views
2K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 2 ·
Replies
2
Views
2K