예제 #1
0
 public static void copyElements(Utils.Stack <Student> src, Utils.Stack <Student> dest)
 {
     Utils.Stack <Student> aux = new Utils.Stack <Student>();
     while (!src.isEmpty())
     {
         try
         {
             aux.push(src.pop());
         }
         catch (MyException e)
         {
             Console.WriteLine(e.Message);
         }
     }
     while (!aux.isEmpty())
     {
         try
         {
             dest.push(aux.pop());
         }
         catch (MyException e)
         {
             Console.WriteLine(e.Message);
         }
     }
 }
예제 #2
0
 public RepositoryStack()
 {
     //Stack repository constructor
     //Preconditions:
     //Postcond: A new empty repository stack object is build
     studentlist = new Utils.Stack <T>();
 }
예제 #3
0
        public bool IsPalinDrome(SinglyLinkedListNode <string> node)
        {
            SinglyLinkedListNode <string> slow = node;
            SinglyLinkedListNode <string> fast = node;
            var buffer = new Utils.Stack <string>();

            while (fast != null && fast.Next != null)
            {
                buffer.Push(slow.Data);
                slow = slow.Next;
                fast = fast.Next.Next;
            }

            if (fast != null && fast.Next != null)
            {
                slow = slow.Next;
            }

            while (slow != null)
            {
                if (buffer.Peek() == slow.Data)
                {
                    buffer.Pop();
                }
                slow = slow.Next;
            }
            return(buffer.IsEmpty());
        }
예제 #4
0
        public List <T> toArray()
        {
            List <T> crepo = new List <T>();

            Utils.Stack <T> stackcopy = this.getAll();
            int             i         = 0;

            while (!stackcopy.isEmpty())
            {
                crepo.Add(stackcopy.pop());
            }
            return(crepo);
        }
예제 #5
0
 public void removeStudent(Object s)
 {
     Utils.Stack <T> aux = new Utils.Stack <T>();
     while (true)
     {
         T ss = this.studentlist.pop();
         if (ss.Equals(s))
         {
             break;
         }
         aux.push(ss);
     }
     while (aux.getSize() != 0)
     {
         this.studentlist.push(aux.pop());
     }
 }