Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace nodeTest
- {
- class Program
- {
- public static void printList(Node<int> ls)
- {
- Node<int> pos1 = ls;
- while (pos1 != null)
- {
- Console.WriteLine(pos1.GetValue());
- pos1 = pos1.GetNext();
- }
- }
- public static Node<int> qu1(Node<int> list1, int max)
- {
- Node<int> newList = new Node<int>(1);
- Node<int> newPos = newList;
- for(int i=2;i< max; i++)
- {
- Node<int> pos1 = list1;
- bool found = false;
- while (pos1 != null)
- {
- if (pos1.GetValue() == i)
- {
- found = true;
- }
- pos1 = pos1.GetNext();
- }
- if (!found)
- {
- newPos.SetNext(new Node<int>(i));
- newPos = newPos.GetNext();
- }
- }
- return newList;
- }
- public static Node<int> qu2(Node<int> L)
- {
- Node<int> Lpos = L;
- Node<int> newList = new Node<int>(0);
- Node<int> newPos = newList;
- int sum = 0;
- int lastNumber = 0;
- while (Lpos != null)
- {
- int value = Lpos.GetValue();
- if (value > lastNumber)
- {
- sum += value;
- lastNumber = value;
- }
- else
- {
- newPos.SetValue(sum);
- newPos.SetNext(new Node<int>(0));
- newPos = newPos.GetNext();
- sum = 0;
- lastNumber = 0;
- }
- Lpos = Lpos.GetNext();
- }
- return newList;
- }
- static void Main(string[] args)
- {
- int value = int.Parse(Console.ReadLine());
- Node<int> ls = new Node<int>(value);
- Node<int> pos = ls;
- value = int.Parse(Console.ReadLine());
- while (value!=999)
- {
- pos.SetNext(new Node<int>(value));
- pos = pos.GetNext();
- value = int.Parse(Console.ReadLine());
- }
- Console.WriteLine("original Node:");
- printList(ls);
- Console.WriteLine("after qu2:");
- printList(qu2(ls));
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement