当前位置: 首页>>代码示例>>C++>>正文


C++ SLNode::next_node方法代码示例

本文整理汇总了C++中SLNode::next_node方法的典型用法代码示例。如果您正苦于以下问题:C++ SLNode::next_node方法的具体用法?C++ SLNode::next_node怎么用?C++ SLNode::next_node使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在SLNode的用法示例。


在下文中一共展示了SLNode::next_node方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: Insert

void SLList::Insert(int contents) {
	if(head_ == NULL) {
		InsertHead(contents);
	}
	else if(contents < GetHead()) {
		InsertHead(contents);
	}
	else if (head_->next_node() == NULL && head_ != NULL) {
		InsertTail(contents);
	}
	else if(contents > GetTail()) {
		InsertTail(contents);
	}
	else {
		SLNode* node = new SLNode(contents);
		SLNode* i = head_;
		SLNode* j = NULL;
		while(i->contents() <= contents && i->next_node() != NULL) {
			j = i;
			i = i->next_node();
		}
		j->set_next_node(node);
		node->set_next_node(i);
		size_++;
	}
}
开发者ID:jacobpicard,项目名称:csci21-spring2016,代码行数:26,代码来源:sl_list.cpp

示例2: RemoveTail

void SLList::RemoveTail()
{
    //removes the tail node from the list, or does nothing if the list is empty
    SLNode *tmp = head_;
    if(tmp != NULL)
    {
        // list is not empty
        if (head_ == tail_)
        {
            // list only has 1 item in it, clear the list
            delete head_;
            head_ = NULL;
            tail_ = NULL;
            size_ = 0;
            return;
        }
        while(tmp->next_node() != tail_)
        {
            // find the item just before the tail
            tmp = tmp->next_node();
        }
        // delete the old tail
        delete tail_;
        // this will be the new end of the list
        tmp->set_next_node(NULL);
        tail_ = tmp;
        size_--;
        return;
    }
}
开发者ID:marieissel,项目名称:csci21-unit3,代码行数:30,代码来源:sl_list.cpp

示例3: Insert

void SLList::Insert(int contents)
{
    if (contents < GetHead() || head_ == NULL)
    {
        InsertHead(contents);
    }
    else if (contents > GetTail())
    {
        InsertTail(contents);
    }
    else
    {
        SLNode *new_node = new SLNode(contents);
        SLNode *it = head_;
        SLNode *temp = it->next_node();
        if (size_ == 2)
        {
            head_->set_next_node(new_node);
            new_node->set_next_node(tail_);
        }
        else
        {
            while (temp->contents() < contents)
            {
                it = temp;
                temp = temp->next_node();
            }
            it->set_next_node(new_node);
            new_node->set_next_node(temp);
        }
        size_++;
    }
}
开发者ID:hdamon001,项目名称:CSCI-21-SPRING-2016,代码行数:33,代码来源:sl_list.cpp

示例4: Insert

void SLList::Insert(int contents)
{
    //Checks if head is null or contents is < head_->contents();
    if (head_ == NULL || head_->contents() > contents)
    {
        InsertHead(contents);
    } else if ( tail_->contents() < contents)
    {
      //  cout << " got it: " << contents << endl;
     //   cout << ToString();
        InsertTail(contents);
    } else 
    {
        //creates iterator and newnode
        SLNode* iterator;
        iterator = head_;
        while (iterator->next_node() != NULL && contents > iterator->next_node()->contents())
        {
        iterator = iterator->next_node();
        }
        if (iterator != tail_)
        {
            SLNode *newNode = new SLNode(contents);
            newNode->set_next_node(iterator->next_node());
            iterator->set_next_node(newNode);
            size_ +=1;
        } else
        {
            InsertTail(contents);
        }
    }
}
开发者ID:Dminer001,项目名称:CSCI-21,代码行数:32,代码来源:sl_list.cpp

示例5: ToString

 /*
  * returns a string representation of the contents
  * of all nodes in the list, in the format
  * NUM1, NUM2, ..., LASTNUM
  * returns the empty string on an empty list (i.e. returns "")
  */
 string SLList::ToString() const
 {
   std::stringstream ss;
   ss.clear();
   ss.str();
   
   SLNode* temp = head_;                                                       //create temp to be an iterator
   
   if(head_ != NULL)
   {
      while(temp->next_node() != NULL)                                         //cycles through the list until null is next
      {
         ss << temp-> contents();
      
         temp = temp->next_node();
       
         ss << ", ";
         
      }   
      ss << temp->contents();                                                  //prints out the last node
   }
   else
   {
       ss << "";
   }
 
   string someString;
 
   someString = ss.str();
 
   return someString;
 }
开发者ID:agonzales004,项目名称:CSCI-21-SPRING-2016,代码行数:38,代码来源:sl_list.cpp

示例6: RemoveFirstOccurence

bool SLList::RemoveFirstOccurence(int data)
{ 
  if(head_) //if there is a list
  {
    if(head_->contents() == data) //if the data is same as head                                          
    {
      RemoveHead();
      return true;
    }
    SLNode* prev = head_; //assign node to head_
    SLNode* current = head_->next_node(); //assign current to node after head
    while(current) //while current is not NULL                                                      
    {
      if(current->contents() == data)  //if current = to data                                      
      {
        prev->set_next_node(current->next_node()); //prev points to the node after current
        if(current == tail_)  //if current = tail, tail assigned to prev                                                     
        {
          tail_ = prev;
        }
        current = NULL; //dereference current
        delete current; //delete current
        size_--; //now we minus the size
        return true;
      }
      prev = current; //these traverse prev before current
      current = current->next_node();
    }
  }
  else
  {
    return false;
  }    
}
开发者ID:JordanLaney,项目名称:CSCI21,代码行数:34,代码来源:sl_list.cpp

示例7: ToString

string SLList::ToString() const {
	stringstream ss;
		for(SLNode* iterator = head_; iterator != NULL; iterator = iterator->next_node()) {
			ss <<  iterator->contents();
			if(iterator->next_node() != NULL) {
			  ss << ", ";
		}
	}
	return ss.str();
}
开发者ID:jacobpicard,项目名称:csci21-spring2016,代码行数:10,代码来源:sl_list.cpp

示例8: GetTail

int SLList::GetTail() {
	if(head_ == NULL) {
		return 0;
	}
	else {
		SLNode* i = head_;
		while(i->next_node() != NULL) {
			i = i->next_node();
		}
		return i->contents();
	}
}
开发者ID:jacobpicard,项目名称:csci21-spring2016,代码行数:12,代码来源:sl_list.cpp

示例9: ToString

string SLList::ToString() //uses string stream to display
{
  stringstream stream;
  for(SLNode* out = head_; out != NULL; out = out->next_node()) //sets out* to head, while not NULL points to next node
  { 
    stream << out->contents(); //puts contents of each node into stream
    if(out->next_node() != NULL) //if the next node is not NULL then is adds a comma for the incoming next node
    {
      stream << ", ";
    }
  }
  return stream.str(); //returns contents of string
}
开发者ID:JordanLaney,项目名称:CSCI21,代码行数:13,代码来源:sl_list.cpp

示例10: InsertTail

void SLList::InsertTail(int newTail) {
	if(head_ == NULL) {
		InsertHead(newTail);
	}
	else {
		SLNode* i = head_;
		while (i->next_node() != NULL) {
			i = i->next_node();
		}
		SLNode* node = new SLNode(newTail);
		i->set_next_node(node);
		size_++;
	}
}
开发者ID:jacobpicard,项目名称:csci21-spring2016,代码行数:14,代码来源:sl_list.cpp

示例11: Insert

void SLList::Insert(int data)
{  
  
  SLNode* insert = new SLNode(data); //assigns data to new node 
  SLNode* current = head_; //assigns head to current
  SLNode* prev = current;
  if(!head_ || data <= current->contents()) //if there is a list or data is less than or equal to head_                                                          
  {
    InsertHead(data); 
  }
  else if(data > tail_->contents()) //if data is greater than tail
  {
    InsertTail(data);
  }
  else
  {
  while(current->contents()  < data) //while current is less than data
  {
    prev = current; //we assign prev to currents position
    current = current->next_node(); //then assign current to next position
  }
  insert->set_next_node(current); //set node at currents position
  prev->set_next_node(insert); //set data at proper position
  size_++;
  }
}
开发者ID:JordanLaney,项目名称:CSCI21,代码行数:26,代码来源:sl_list.cpp

示例12: ToString

/**
 * returns a string representation of the contents
 * of all nodes in the list, in the format
 * NUM1, NUM2, ..., LASTNUM
 * returns the empty string on an empty list (i.e. returns "")
 */
string SLList::ToString() const
{
    if (head_ == NULL)
    return "";
    stringstream ss;
        SLNode* temp = head_;
        
            while (temp != NULL)
            {
                ss << temp->contents();
                if (temp->next_node() != NULL)
                ss << ", ";
                temp = temp->next_node();
            }
    
    
    return ss.str();
}
开发者ID:Dminer001,项目名称:CSCI-21,代码行数:24,代码来源:sl_list.cpp

示例13: RemoveTail

void SLList::RemoveTail() {
	if(head_ == NULL) {
		//DO NOTHING
	}
	else if (head_->next_node() == NULL) {
		RemoveHead();
	}
	else {
	SLNode* i = head_;
	SLNode* j = NULL;
		while (i->next_node() != NULL) {
			j = i;
			i = i->next_node();
		}
		delete i;
		j->set_next_node(NULL);
		size_--;
	}
}
开发者ID:jacobpicard,项目名称:csci21-spring2016,代码行数:19,代码来源:sl_list.cpp

示例14: RemoveTail

void SLList::RemoveTail()
{
  if(head_ && size_ >= 2) //we need to know that there is a list bigger that 1 before we remove tail
  { 
    SLNode* remove_tail = tail_;
    SLNode* current = head_; //new pointer assigned to head
    while(current->next_node() != tail_)//traverses list while not at tail position
    {
      current = current->next_node();
    }
    tail_ = current;
    tail_->set_next_node(NULL);
    delete remove_tail;
    size_--;
  }
  else if(size_ == 1) //checks if the size is one
  {
    head_ = NULL; //assigns head to null
    size_ = 0; //set size to 0
  }
}      
开发者ID:JordanLaney,项目名称:CSCI21,代码行数:21,代码来源:sl_list.cpp

示例15: RemoveFirstOccurence

bool SLList::RemoveFirstOccurence(int contents) {
	SLNode* node = new SLNode(contents);
	if (contents == GetHead()) {
		RemoveHead();
		return true;
	}
	else if(contents == GetTail()) {
		RemoveTail();
		return true;
	}
	else if(head_ == NULL) {
		return false;
	}
	else if (node == NULL) {
		return false;
	}
	else if (contents != GetHead() && contents != GetTail()) {
		SLNode* i = head_;
		SLNode* j = NULL;
		while (i->contents() != contents && i->next_node() != NULL) {
			j = i;
			i = i->next_node();
		}
		if(i->next_node() == NULL && i->contents() != contents) {
			return false;
		}
		else {
			SLNode* temp = i->next_node();
			SLNode* temp2 = i;
			delete temp2;
			j->set_next_node(temp);
			size_--;
			return true;
		}
	}
	else
		return false;
}
开发者ID:jacobpicard,项目名称:csci21-spring2016,代码行数:38,代码来源:sl_list.cpp


注:本文中的SLNode::next_node方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。