本文整理汇总了C++中SLNode::getNextNode方法的典型用法代码示例。如果您正苦于以下问题:C++ SLNode::getNextNode方法的具体用法?C++ SLNode::getNextNode怎么用?C++ SLNode::getNextNode使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SLNode
的用法示例。
在下文中一共展示了SLNode::getNextNode方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: removeFirst
bool SList::removeFirst(int contents) {
SLNode* toRemove = NULL;
SLNode* nodeMark = head;
SLNode* lagMark = NULL;
for (unsigned int i = 0; i < size; i++){
if (nodeMark->getContents() != contents && nodeMark->getNextNode() != NULL){
lagMark = nodeMark;
nodeMark = nodeMark->getNextNode();
} else if (nodeMark->getContents() == contents){
toRemove = nodeMark;
}
}
if (toRemove == NULL) {
return false;
}
if (lagMark == NULL){
removeHead();
} else if (toRemove->getNextNode() == NULL) {
removeTail();
} else {
size--;
nodeMark = nodeMark->getNextNode();
lagMark->setNextNode(nodeMark);
delete toRemove;
}
toRemove = NULL;
nodeMark = NULL;
lagMark = NULL;
return true;
}
示例2: removeFirst
bool SList::removeFirst (int target) {
if (head == NULL)
return false;
else {
SLNode* trailer = NULL;
SLNode* leader = head;
while (leader != NULL && leader->getContents() != target) {
trailer = leader;
leader = leader->getNextNode();
}
if (leader == NULL) {
return false;
}
else if (leader == head) {
removeHead();
return true;
}
else {
trailer->setNextNode(leader->getNextNode());
delete leader;
--numNodes;
return true;
}
}
}
示例3: toString
//Prints the contents of the list in the format: NUM1,NUM2,...,LASTNUM
//Empty string on empty list
std::string SList::toString() const{
std::string listContents = "";
SLNode *p = head;
std::stringstream ss;
unsigned int count;
if(p == NULL){
return "";
}
count = 0;
while(p != NULL){
if(count == 0){
ss << p->getContents();
//listContents += (std::to_string(p->getContents()));
p = p->getNextNode();
count++;
}else{
ss << ',' << p->getContents();
//listContents += (',' + std::to_string(p->getContents()));
p = p->getNextNode();
}
}
listContents = ss.str();
return listContents;
}
示例4: toString
string SList::toString () const{
stringstream ss;
for(SLNode* i = head; i != NULL; i = i->getNextNode()){
ss << i->getContents();
if(i->getNextNode() != NULL)
ss << ",";
}
return ss.str();
}
示例5: toString
string SList::toString () const {
//Need to include sstream for this.
stringstream ss;
//Fetch the contents.
for (SLNode* i = head; i != NULL; i=i->getNextNode()) {
ss << i->getContents();
if(i->getNextNode() != NULL)
ss << ',';
}
return ss.str();
}
示例6: insertTail
void SList::insertTail (int contents) {
if(head == NULL){
insertHead(contents);
}
else {
SLNode* i = head;
while (i->getNextNode() !=NULL) {
i=i->getNextNode();
}
SLNode* node = new SLNode(contents);
i->setNextNode(node);
size++;
}
}
示例7: insertTail
void SList::insertTail (int newTail) {
SLNode* temp = new SLNode(newTail);
if (head == NULL) {
insertHead(newTail);
}
else {
SLNode* i = head;
while (i->getNextNode() != NULL) {
i = i->getNextNode();
}
i->setNextNode(temp);
size++;
}
}
示例8: insertTail
void SList::insertTail (int contents) {
if (head == NULL) {
insertHead(contents);
}
else {
SLNode* i = head;
SLNode* newNode = new SLNode(contents);
while (i->getNextNode() != NULL) {
i = i->getNextNode();
}
i->setNextNode(newNode);
++numNodes;
}
}
示例9: insertTail
void SList::insertTail (int contents) {
SLNode* temp = new SLNode(contents);
temp->setNextNode(NULL);
if (head == NULL) {
head = temp;
} else {
SLNode* tail = head;
while (tail->getNextNode() != NULL) {
tail = tail->getNextNode();
}
tail->setNextNode(temp);
}
size++;
}
示例10: insertTail
void SList::insertTail(int value)
{
if(head == NULL)
{
insertHead(value);
}
else
{
SLNode* newNode = new SLNode(value);
SLNode* temp = head;
while(temp->getNextNode() != NULL)
{
temp = temp->getNextNode();
}
temp->setNextNode(newNode);
size++;
}
}// create a new SLNode and attach at the end of list
示例11: removeTail
void SList::removeTail () {
if(head == NULL){
}
else if (head->getNextNode()==NULL) {
removeHead();
} else {
SLNode* i = head;
SLNode* j=NULL;
while (i->getNextNode() !=NULL) {
j=i;
i=i->getNextNode();
}
delete i;
j->setNextNode(NULL);
size--;
}
}
示例12: removeTail
void SList::removeTail () {
if (head != NULL) {
if (head->getNextNode() == NULL) {
delete head;
head = NULL;
} else {
SLNode* nextToTail = head;
SLNode* tail = head->getNextNode();
while (tail->getNextNode() != NULL) {
nextToTail = tail;
tail = tail->getNextNode();
}
delete tail;
nextToTail->setNextNode(NULL);
}
size--;
}
}
示例13: insertTail
void SList::insertTail (int contents){
if(head != NULL) {
//Finds the tail.
SLNode* i = head;
while (i->getNextNode() != NULL) {
//Starts at head and moves it over to the last node.
i = i->getNextNode();
}
SLNode* node = new SLNode(contents);
//points at the end and inserts the new node that was just created.
i->setNextNode(node);
size++;
} else {
//Empty list - make it to insert head as it's the same thing.
insertHead(contents);
}
}
示例14: toString
string SList::toString() const {
string listContents;
stringstream ss;
if (head != NULL){
ss << head->getContents();
if (head->getNextNode() != NULL){
SLNode* currentNode = head->getNextNode();
for (unsigned int i = 1; i < size; i++){
ss << ",";
ss << currentNode->getContents();
if (currentNode->getNextNode() != NULL){
currentNode = currentNode->getNextNode();
}
}
}
}
ss >> listContents;
return listContents;
}
示例15: removeTail
void SList::removeTail () {
if (head != NULL) {
SLNode* i = head;
SLNode* trailer = NULL;
while (i->getNextNode() != NULL) {
trailer = i;
i = i->getNextNode();
}
delete i;
--numNodes;
if (trailer == NULL) {
head = NULL;
}
else {
trailer->setNextNode(NULL);
}
}
}