public Page addPage(int PageId, String title)
        {
            // currently sorted by text
            // should be fewer pages by that
            //possibly seperate list to sort by int to increase search speed?
            Page newEntry = new Page(PageId, title);
            if (PageList == null)
            {
                PageList = newEntry;
            }
            else
            {
                Page temp = PageList;
                while (temp != null)
                {
                    if (newEntry.compareTo(temp) == 0)
                    {
                        // add all id lines to page//store id in Page as list
                        //delete newEntry or set to null
                        newEntry = temp;
                        break;
                    }
                    else
                    {

                        if (temp == PageList && newEntry.compareTo(temp) < 0)
                        {
                            //insert newEntry as new PageList Head and shift old PageList down
                            temp.setPrev(newEntry);
                            newEntry.setNext(temp);
                            PageList = newEntry;
                            break;
                        }
                        else if ( temp.getNext() == null )
                        {
                            temp.setNext(newEntry);
                            newEntry.setPrev(temp);
                            break;
                        }
                        else if ((newEntry.compareTo(temp) > 0) && (newEntry.compareTo(temp.getNext()) < 0))
                        {
                            //add newEntry between
                            newEntry.setPrev(temp);
                            newEntry.setNext(temp.getNext() );
                            newEntry.getNext().setPrev(newEntry);
                            temp.setNext(newEntry);

                            break;
                        }
                        else
                        {
                            temp = temp.getNext();
                        }
                    }
                }
            }
            return newEntry;
        }
Exemple #2
0
 public int compareTo(Page B)
 {
     if (getTitle().Equals(B.getTitle()))
     {
         return 0;
     }
     else
     {
         return String.Compare(getTitle(), B.getTitle(), StringComparison.OrdinalIgnoreCase);
     }
 }
Exemple #3
0
 public void setPrev(Page newPrev)
 {
     prev = newPrev;
 }
Exemple #4
0
 public void setNext(Page newNext)
 {
     next = newNext;
 }