SNAP Library 2.1, User Reference  2013-09-25 10:47:25
SNAP, a general purpose, high performance system for analysis and manipulation of large networks
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
TLst< TVal > Class Template Reference

#include <ds.h>

List of all members.

Public Types

typedef TLstNd< TVal > * PLstNd

Public Member Functions

 TLst ()
 TLst (const TLst &)
 ~TLst ()
 TLst (TSIn &SIn)
void Save (TSOut &SOut) const
TLstoperator= (const TLst &)
void Clr ()
bool Empty () const
int Len () const
PLstNd First () const
PLstNd Last () const
TVal & FirstVal () const
TVal & LastVal () const
PLstNd AddFront (const TVal &Val)
PLstNd AddBack (const TVal &Val)
PLstNd AddFrontSorted (const TVal &Val, const bool &Asc=true)
PLstNd AddBackSorted (const TVal &Val, const bool &Asc=true)
void PutFront (const PLstNd &Nd)
void PutBack (const PLstNd &Nd)
PLstNd Ins (const PLstNd &Nd, const TVal &Val)
void Del (const TVal &Val)
void Del (const PLstNd &Nd)
void DelFirst ()
void DelLast ()
PLstNd SearchForw (const TVal &Val)
PLstNd SearchBack (const TVal &Val)

Private Attributes

int Nds
PLstNd FirstNd
PLstNd LastNd

Friends

class TLstNd< TVal >

Detailed Description

template<class TVal>
class TLst< TVal >

Definition at line 3571 of file ds.h.


Member Typedef Documentation

template<class TVal>
typedef TLstNd<TVal>* TLst< TVal >::PLstNd

Definition at line 3573 of file ds.h.


Constructor & Destructor Documentation

template<class TVal>
TLst< TVal >::TLst ( ) [inline]

Definition at line 3579 of file ds.h.

: Nds(0), FirstNd(NULL), LastNd(NULL){}
template<class TVal>
TLst< TVal >::TLst ( const TLst< TVal > &  )
template<class TVal>
TLst< TVal >::~TLst ( ) [inline]

Definition at line 3581 of file ds.h.

{Clr();}
template<class TVal >
TLst< TVal >::TLst ( TSIn SIn) [explicit]

Definition at line 3618 of file ds.h.

                         :
  Nds(0), FirstNd(NULL), LastNd(NULL){
  int CheckNds=0; SIn.Load(CheckNds);
  for (int NdN=0; NdN<CheckNds; NdN++){AddBack(TVal(SIn));}
  Assert(Nds==CheckNds);
}

Member Function Documentation

template<class TVal>
TLstNd< TVal > * TLst< TVal >::AddBack ( const TVal &  Val)

Definition at line 3643 of file ds.h.

                                                {
  PLstNd Nd=new TLstNd<TVal>(LastNd, NULL, Val);
  if (LastNd!=NULL){LastNd->NextNd=Nd; LastNd=Nd;}
  else {FirstNd=Nd; LastNd=Nd;}
  Nds++; return Nd;
}
template<class TVal>
TLstNd< TVal > * TLst< TVal >::AddBackSorted ( const TVal &  Val,
const bool &  Asc = true 
)

Definition at line 3664 of file ds.h.

                                                                       {
  PLstNd Nd=Last();
  while ((Nd!=NULL)&&((Asc&&(Val<Nd->Val))||(!Asc&&(Val>Nd->Val)))){
    Nd=Nd->Prev();}
  return Ins(Nd, Val);
}
template<class TVal>
TLstNd< TVal > * TLst< TVal >::AddFront ( const TVal &  Val)

Definition at line 3635 of file ds.h.

                                                 {
  PLstNd Nd=new TLstNd<TVal>(NULL, FirstNd, Val);
  if (FirstNd!=NULL){FirstNd->PrevNd=Nd; FirstNd=Nd;}
  else {FirstNd=Nd; LastNd=Nd;}
  Nds++; return Nd;
}
template<class TVal>
TLstNd< TVal > * TLst< TVal >::AddFrontSorted ( const TVal &  Val,
const bool &  Asc = true 
)

Definition at line 3651 of file ds.h.

                                                                        {
  PLstNd Nd=First();
  if (Nd==NULL){
    return Ins(Nd, Val);
  } else {
    while ((Nd!=NULL)&&((Asc&&(Val>Nd()))||(!Asc&&(Val<Nd())))){
      Nd=Nd->Next();}
    if (Nd==NULL){return Ins(Nd->Last(), Val);}
    else {return Ins(Nd->Prev(), Val);}
  }
}
template<class TVal>
void TLst< TVal >::Clr ( ) [inline]

Definition at line 3587 of file ds.h.

            {
    PLstNd Nd=FirstNd;
    while (Nd!=NULL){PLstNd NextNd=Nd->NextNd; delete Nd; Nd=NextNd;}
    Nds=0; FirstNd=NULL; LastNd=NULL;}
template<class TVal>
void TLst< TVal >::Del ( const TVal &  Val)

Definition at line 3711 of file ds.h.

                                   {
  PLstNd Nd=SearchForw(Val);
  if (Nd!=NULL){Del(Nd);}
}
template<class TVal>
void TLst< TVal >::Del ( const PLstNd Nd)

Definition at line 3717 of file ds.h.

                                    {
  Assert(Nd!=NULL);
  if (Nd->PrevNd==NULL){FirstNd=Nd->NextNd;}
  else {Nd->PrevNd->NextNd=Nd->NextNd;}
  if (Nd->NextNd==NULL){LastNd=Nd->PrevNd;}
  else {Nd->NextNd->PrevNd=Nd->PrevNd;}
  Nds--; delete Nd;
}
template<class TVal>
void TLst< TVal >::DelFirst ( ) [inline]

Definition at line 3608 of file ds.h.

{ PLstNd DelNd = FirstNd; Del(DelNd); }
template<class TVal>
void TLst< TVal >::DelLast ( ) [inline]

Definition at line 3609 of file ds.h.

{ PLstNd DelNd = LastNd; Del(DelNd); }
template<class TVal>
bool TLst< TVal >::Empty ( ) const [inline]

Definition at line 3592 of file ds.h.

{return Nds==0;}
template<class TVal>
PLstNd TLst< TVal >::First ( ) const [inline]

Definition at line 3594 of file ds.h.

{return FirstNd;}
template<class TVal>
TVal& TLst< TVal >::FirstVal ( ) const [inline]

Definition at line 3596 of file ds.h.

{return FirstNd->GetVal();}
template<class TVal>
TLstNd< TVal > * TLst< TVal >::Ins ( const PLstNd Nd,
const TVal &  Val 
)

Definition at line 3700 of file ds.h.

                                                              {
  if (Nd==NULL){return AddFront(Val);}
  else if (Nd->NextNd==NULL){return AddBack(Val);}
  else {
    PLstNd NewNd=new TLstNd<TVal>(Nd, Nd->NextNd, Val);
    Nd->NextNd=NewNd; NewNd->NextNd->PrevNd=Nd;
    Nds++; return Nd;
  }
}
template<class TVal>
PLstNd TLst< TVal >::Last ( ) const [inline]

Definition at line 3595 of file ds.h.

{return LastNd;}
template<class TVal>
TVal& TLst< TVal >::LastVal ( ) const [inline]

Definition at line 3597 of file ds.h.

{return LastNd->GetVal();}
template<class TVal>
int TLst< TVal >::Len ( ) const [inline]

Definition at line 3593 of file ds.h.

{return Nds;}
template<class TVal>
TLst& TLst< TVal >::operator= ( const TLst< TVal > &  )
template<class TVal >
void TLst< TVal >::PutBack ( const PLstNd Nd)

Definition at line 3686 of file ds.h.

                                        {
  Assert(Nd!=NULL);
  // unchain
  if (Nd->PrevNd==NULL){FirstNd=Nd->NextNd;}
  else {Nd->PrevNd->NextNd=Nd->NextNd;}
  if (Nd->NextNd==NULL){LastNd=Nd->PrevNd;}
  else {Nd->NextNd->PrevNd=Nd->PrevNd;}
  // add to back
  Nd->PrevNd=LastNd; Nd->NextNd=NULL;
  if (LastNd!=NULL){LastNd->NextNd=Nd; LastNd=Nd;}
  else {FirstNd=Nd; LastNd=Nd;}
}
template<class TVal >
void TLst< TVal >::PutFront ( const PLstNd Nd)

Definition at line 3672 of file ds.h.

                                         {
  Assert(Nd!=NULL);
  // unchain
  if (Nd->PrevNd==NULL){FirstNd=Nd->NextNd;}
  else {Nd->PrevNd->NextNd=Nd->NextNd;}
  if (Nd->NextNd==NULL){LastNd=Nd->PrevNd;}
  else {Nd->NextNd->PrevNd=Nd->PrevNd;}
  // add to front
  Nd->PrevNd=NULL; Nd->NextNd=FirstNd;
  if (FirstNd!=NULL){FirstNd->PrevNd=Nd; FirstNd=Nd;}
  else {FirstNd=Nd; LastNd=Nd;}
}
template<class TVal >
void TLst< TVal >::Save ( TSOut SOut) const

Definition at line 3626 of file ds.h.

                                       {
  SOut.Save(Nds);
  PLstNd Nd=FirstNd; int CheckNds=0;
  while (Nd!=NULL){
    Nd->Val.Save(SOut); Nd=Nd->NextNd; CheckNds++;}
  IAssert(Nds==CheckNds);
}
template<class TVal>
TLstNd< TVal > * TLst< TVal >::SearchBack ( const TVal &  Val)

Definition at line 3737 of file ds.h.

                                                   {
  PLstNd Nd=Last();
  while (Nd!=NULL){
    if (Nd->GetVal()==Val){return Nd;}
    Nd=Nd->Prev();
  }
  return NULL;
}
template<class TVal>
TLstNd< TVal > * TLst< TVal >::SearchForw ( const TVal &  Val)

Definition at line 3727 of file ds.h.

                                                   {
  PLstNd Nd=First();
  while (Nd!=NULL){
    if (Nd->GetVal()==Val){return Nd;}
    Nd=Nd->Next();
  }
  return NULL;
}

Friends And Related Function Documentation

template<class TVal>
friend class TLstNd< TVal > [friend]

Definition at line 3614 of file ds.h.


Member Data Documentation

template<class TVal>
PLstNd TLst< TVal >::FirstNd [private]

Definition at line 3576 of file ds.h.

template<class TVal>
PLstNd TLst< TVal >::LastNd [private]

Definition at line 3577 of file ds.h.

template<class TVal>
int TLst< TVal >::Nds [private]

Definition at line 3575 of file ds.h.


The documentation for this class was generated from the following file: