Link class' add, erase, find and advance member functions

18 views
Skip to first unread message

Osman Zakir

unread,
Sep 7, 2017, 4:24:39 PM9/7/17
to PPP-public
I want to ask if I got them right, and to ask how to fix them otherwise.

Link *Link::add(Link *n)
{
 
if (n == nullptr)
 
{
 
return this;
 
}
 
if (this == nullptr)
 
{
 
return n;
 
}
 n
->prev = this;
 
if (succ)
 
{
  succ
->prev = n;
 
}
 n
->succ = succ;
 succ
= n;
 
return n;
}

Link *Link::erase()
{
 
if (this == nullptr)
 
{
 
return nullptr;
 
}
 
if (succ)
 
{
  succ
->prev = prev;
 
}
 
if (prev)
 
{
  prev
->succ = succ;
 
}
 
return succ;
}

Link *Link::find(const std::string &s)
{
 
while (this != nullptr)
 
{
 
if (value == s)
 
{
   
return this;
 
}
 
this->succ;
 
}
 
return nullptr;
}

const Link *Link::find(const std::string &s) const
{
 
while (this != nullptr)
 
{
 
if (value == s)
 
{
   
return this;
 
}
 
this->succ;
 
}
 
return nullptr;
}

Link *Link::advance(int n) const
{
 
if (this == nullptr)
 
{
 
return nullptr;
 
}
 
if (n > 0)
 
{
 
while (n--)
 
{
   
if (succ == nullptr)
   
{
   
return nullptr;
   
}
 
}
 
}
 
else if (n < 0)
 
{
 
while (n++)
 
{
   
if (prev == nullptr)
   
{
   
return nullptr;
   
}
 
}
 
}
 
return const_cast<Link *>(this);
}

I'm not sure if I got it right, so it'd be appreciated if someone would please help me out here.  Thanks in advance.
Reply all
Reply to author
Forward
0 new messages