public void addtask(Task t)
 {
     if (num == 0 || t.GetCode() == 1)
     {
         tasks.push(t);
     }
     else
     {
         stack <Task> s1   = copy(tasks);
         stack <Task> temp = new stack <Task>();
         while (s1.Top().GetCode() < t.GetCode())
         {
             temp.push(s1.Pop());
             if (s1.Top() == null)
             {
                 break;
             }
         }
         s1.push(t);
         while (!temp.isEmpty())
         {
             s1.push(temp.Pop());
         }
     }
     num++;
 }
Пример #2
0
        static stack <string> nodups(stack <string> s)
        {
            stack <string> s1 = copy(s);              //the one that is checking the stack one at a time
            stack <string> s2 = new stack <string>(); //new
            stack <string> s3 = new stack <string>(); //new temp

            while (!s1.isEmpty())
            {
                bool add = true;
                s3 = copy(s2);
                stack <string> s4 = copy(s1); //running thru it to compare
                while (!s4.isEmpty())
                {
                    while (!s2.isEmpty())
                    {
                        if (s2.Pop() == s4.Top())
                        {
                            add = false;
                        }
                    }
                    s4.Pop();
                }
                s2 = copy(s3);
                if (add)
                {
                    s2.push(s1.Top());
                }
                s1.Pop();
            }

            return(s3);
        }
Пример #3
0
        static stack <string> nodupscount(stack <string> s)
        {
            stack <string> s1 = copy(s);              //the one that is checking the stack one at a time
            stack <string> s2 = new stack <string>(); //new
            stack <string> s3 = new stack <string>(); //new temp
            stack <string> s5 = new stack <string>(); //answer

            while (!s1.isEmpty())
            {
                bool add = true;
                s3 = copy(s2);
                stack <string> s4 = copy(s1); //running thru it to compare
                while (!s4.isEmpty())
                {
                    while (!s2.isEmpty())
                    {
                        if (s2.Pop() == s4.Top())
                        {
                            add = false;
                        }
                    }
                    s4.Pop();
                }
                s2 = copy(s3);
                if (add)
                {
                    s2.push(s1.Top());

                    int            counter = 0;
                    stack <string> temp    = copy(s);
                    while (!temp.isEmpty())
                    {
                        if (s1.Top() == temp.Pop())
                        {
                            counter++;
                        }
                    }

                    s5.push(s1.Top() + "=" + counter.ToString() + ",");
                }
                s1.Pop();
            }

            return(s5);
        }
        stack <Task> copy(stack <Task> s)
        {
            stack <Task> s1 = new stack <Task>();
            stack <Task> s2 = new stack <Task>();


            while (!s.isEmpty())
            {
                s1.push(s.Pop());
            }
            while (!s1.isEmpty())
            {
                s.push(s1.Top());
                s2.push(s1.Pop());
            }

            return(s2);
        }
Пример #5
0
        static stack <string> copy(stack <string> s)
        {
            stack <string> s1 = new stack <string>();
            stack <string> s2 = new stack <string>();


            while (!s.isEmpty())
            {
                s1.push(s.Pop());
            }
            while (!s1.isEmpty())
            {
                s.push(s1.Top());
                s2.push(s1.Pop());
            }

            return(s2);
        }