Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static void RemoveSeq(Node<int> p) //Removes recurring digits in a sequence - 8,4,4,4,4,2 -> 8,4,2
- {
- Node<int> t = p, temp;
- while (t.GetNext() != null)
- {
- temp = t.GetNext();
- if(t.GetValue() == temp.GetValue())
- {
- t.SetNext(temp.GetNext());
- temp.SetNext(null);
- }
- else
- {
- t = t.GetNext();
- }
- }
- }
- public static Node<int> RemoveNum(Node<int> p, int n) //Removes all occurrences of digit "n" in list, returning the first node of the new list
- {
- Node<int> t, temp;
- while (p != null && p.GetValue() == n) //Remove all starting nodes of value "n"
- {
- t = p.GetNext();
- p.SetNext(null);
- p = t;
- }
- t = p; temp = p.GetNext();
- while (temp != null) //Removes all other nodes of value "n"
- {
- if(temp.GetValue() != n)
- {
- t = temp;
- temp = temp.GetNext();
- }
- else
- {
- t.SetNext(temp.GetNext());
- temp = t.GetNext();
- }
- }
- return p;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement