ROOT logo
// @(#)root/cont:$Id$
// Author: Fons Rademakers   14/09/95

/*************************************************************************
 * Copyright (C) 1995-2000, Rene Brun and Fons Rademakers.               *
 * All rights reserved.                                                  *
 *                                                                       *
 * For the licensing terms see $ROOTSYS/LICENSE.                         *
 * For the list of contributors see $ROOTSYS/README/CREDITS.             *
 *************************************************************************/

//////////////////////////////////////////////////////////////////////////
//                                                                      //
// A sorted doubly linked list. All sortable classes inheriting from    //
// TObject can be inserted in a TSortedList.                            //
//                                                                      //
//////////////////////////////////////////////////////////////////////////

#include "TSortedList.h"


ClassImp(TSortedList)

//______________________________________________________________________________
void TSortedList::Add(TObject *obj)
{
   // Add object in sorted list. Uses object Compare() member to find right
   // position.

   if (IsArgNull("Add", obj)) return;

   if (!obj->IsSortable()) {
      Error("Add", "object must be sortable");
      return;
   }

   if (!fFirst) {
      TList::AddLast(obj);
      return;
   }

   TObjLink *lnk = fFirst;

   while (lnk) {
      Int_t cmp = lnk->GetObject()->Compare(obj);
      if ((IsAscending() && cmp > 0) || (!IsAscending() && cmp < 0)) {
         if (lnk->Prev()) {
            NewLink(obj, lnk->Prev());
            fSize++;
            return;
         } else {
            TList::AddFirst(obj);
            return;
         }
      }
      lnk = lnk->Next();
   }
   TList::AddLast(obj);
}

//______________________________________________________________________________
void TSortedList::Add(TObject *obj, Option_t *opt)
{
   // Add object in sorted list. Uses object Compare() member to find right
   // position and also store option. See TList::Add for explanation of
   // usage of option.

   if (IsArgNull("Add", obj)) return;

   if (!obj->IsSortable()) {
      Error("Add", "object must be sortable");
      return;
   }

   if (!fFirst) {
      TList::Add(obj, opt);
      return;
   }

   TObjLink *lnk = fFirst;

   while (lnk) {
      Int_t cmp = lnk->GetObject()->Compare(obj);
      if ((IsAscending() && cmp > 0) || (!IsAscending() && cmp < 0)) {
         if (lnk->Prev()) {
            NewOptLink(obj, opt, lnk);
            fSize++;
            return;
         } else {
            TList::AddFirst(obj, opt);
            return;
         }
      }
      lnk = lnk->Next();
   }
   TList::Add(obj, opt);
}
 TSortedList.cxx:1
 TSortedList.cxx:2
 TSortedList.cxx:3
 TSortedList.cxx:4
 TSortedList.cxx:5
 TSortedList.cxx:6
 TSortedList.cxx:7
 TSortedList.cxx:8
 TSortedList.cxx:9
 TSortedList.cxx:10
 TSortedList.cxx:11
 TSortedList.cxx:12
 TSortedList.cxx:13
 TSortedList.cxx:14
 TSortedList.cxx:15
 TSortedList.cxx:16
 TSortedList.cxx:17
 TSortedList.cxx:18
 TSortedList.cxx:19
 TSortedList.cxx:20
 TSortedList.cxx:21
 TSortedList.cxx:22
 TSortedList.cxx:23
 TSortedList.cxx:24
 TSortedList.cxx:25
 TSortedList.cxx:26
 TSortedList.cxx:27
 TSortedList.cxx:28
 TSortedList.cxx:29
 TSortedList.cxx:30
 TSortedList.cxx:31
 TSortedList.cxx:32
 TSortedList.cxx:33
 TSortedList.cxx:34
 TSortedList.cxx:35
 TSortedList.cxx:36
 TSortedList.cxx:37
 TSortedList.cxx:38
 TSortedList.cxx:39
 TSortedList.cxx:40
 TSortedList.cxx:41
 TSortedList.cxx:42
 TSortedList.cxx:43
 TSortedList.cxx:44
 TSortedList.cxx:45
 TSortedList.cxx:46
 TSortedList.cxx:47
 TSortedList.cxx:48
 TSortedList.cxx:49
 TSortedList.cxx:50
 TSortedList.cxx:51
 TSortedList.cxx:52
 TSortedList.cxx:53
 TSortedList.cxx:54
 TSortedList.cxx:55
 TSortedList.cxx:56
 TSortedList.cxx:57
 TSortedList.cxx:58
 TSortedList.cxx:59
 TSortedList.cxx:60
 TSortedList.cxx:61
 TSortedList.cxx:62
 TSortedList.cxx:63
 TSortedList.cxx:64
 TSortedList.cxx:65
 TSortedList.cxx:66
 TSortedList.cxx:67
 TSortedList.cxx:68
 TSortedList.cxx:69
 TSortedList.cxx:70
 TSortedList.cxx:71
 TSortedList.cxx:72
 TSortedList.cxx:73
 TSortedList.cxx:74
 TSortedList.cxx:75
 TSortedList.cxx:76
 TSortedList.cxx:77
 TSortedList.cxx:78
 TSortedList.cxx:79
 TSortedList.cxx:80
 TSortedList.cxx:81
 TSortedList.cxx:82
 TSortedList.cxx:83
 TSortedList.cxx:84
 TSortedList.cxx:85
 TSortedList.cxx:86
 TSortedList.cxx:87
 TSortedList.cxx:88
 TSortedList.cxx:89
 TSortedList.cxx:90
 TSortedList.cxx:91
 TSortedList.cxx:92
 TSortedList.cxx:93
 TSortedList.cxx:94
 TSortedList.cxx:95
 TSortedList.cxx:96
 TSortedList.cxx:97