Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Text;
- using Unit4.CollectionsLib;
- namespace NodeExamples
- {
- class Ex24P122
- {
- public static int ReadGrades()
- {
- Node<int> list = null;
- Node<int> pos = null;
- Console.Write("enter grade: ");
- int x = int.Parse(Console.ReadLine());
- while (x != 999)
- {
- // do somthing
- if (list == null)
- {
- list = new Node<int>(x);
- pos = list;
- }
- else
- {
- pos.SetNext(new Node<int>(x));
- pos = pos.GetNext();
- }
- // get a nuew grade
- Console.Write("enter grade: ");
- x = int.Parse(Console.ReadLine());
- }
- int lastGrade = pos.GetValue();
- int count = 0;
- Node<int> p = list;
- //pos = list;
- while (p != null)
- {
- if (p.GetValue() > lastGrade)
- {
- count++;
- }
- p = p.GetNext();
- }
- return count;
- }
- public static Node<int> ReadGrades2()
- {
- Node<int> list = null;
- Node<int> pos = null;
- Console.Write("enter grade: ");
- int x = int.Parse(Console.ReadLine());
- while (x != 999)
- {
- // do somthing
- if (list == null)
- {
- list = new Node<int>(x);
- pos = list;
- }
- else
- {
- pos.SetNext(new Node<int>(x));
- pos = pos.GetNext();
- }
- // get a nuew grade
- Console.Write("enter grade: ");
- x = int.Parse(Console.ReadLine());
- }
- int lastGrade = pos.GetValue();
- Node<int> p = list;
- Node<int> res = null;
- Node<int> last = null;
- while (p != null)
- {
- if (p.GetValue() > lastGrade)
- {
- if (res == null)
- {
- res = new Node<int>(p.GetValue());
- last = res;
- }
- else
- {
- last.SetNext(new Node<int>(p.GetValue()));
- last = last.GetNext();
- }
- }
- p = p.GetNext();
- }
- return res;
- }
- public static Unit4.CollectionsLib.Stack<int> ReadGrades3()
- {
- Node<int> list = null;
- Node<int> pos = null;
- Console.Write("enter grade: ");
- int x = int.Parse(Console.ReadLine());
- while (x != 999)
- {
- // do somthing
- if (list == null)
- {
- list = new Node<int>(x);
- pos = list;
- }
- else
- {
- pos.SetNext(new Node<int>(x));
- pos = pos.GetNext();
- }
- // get a nuew grade
- Console.Write("enter grade: ");
- x = int.Parse(Console.ReadLine());
- }
- int lastGrade = pos.GetValue();
- Node<int> p = list;
- Unit4.CollectionsLib.Stack<int> stk = new Unit4.CollectionsLib.Stack<int>();
- while (p != null)
- {
- if (p.GetValue() > lastGrade)
- {
- stk.Push(p.GetValue());
- }
- p = p.GetNext();
- }
- return stk;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement