本文整理汇总了C++中SLNode::getContents方法的典型用法代码示例。如果您正苦于以下问题:C++ SLNode::getContents方法的具体用法?C++ SLNode::getContents怎么用?C++ SLNode::getContents使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SLNode
的用法示例。
在下文中一共展示了SLNode::getContents方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: 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;
}
示例2: 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;
}
示例3: 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;
}
}
}
示例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 << ",";
}
string list = ss.str();
return list;
}
示例5: toString
string SList::toString()
{
stringstream list;
SLNode* temp = head;
if(head == NULL)
{
return list.str();
}
else
{
while(temp->getNextNode() != NULL)
{
list << temp->getContents() << ",";
temp = temp->getNextNode();
}
list << temp->getContents();
}
return list.str();
}
示例6: 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();
}
示例7: insert
void SList::insert (int newContents) {
if (head == NULL) {
insertHead (newContents);
}
else if (head->getNextNode() == NULL) {
if (newContents < head->getContents()) {
insertHead(newContents);
}
else {
insertTail(newContents);
}
}
else {
SLNode* trailer = NULL;
SLNode* leader = head;
while (leader->getNextNode() != NULL && newContents > leader->getContents()) {
trailer = leader;
leader = leader->getNextNode();
}
if (leader->getNextNode() == NULL && newContents > leader->getContents()) {
insertTail(newContents);
}
else {
SLNode* theNode = new SLNode (newContents);
theNode->setNextNode(leader);
if (trailer == NULL) {
head = theNode;
numNodes++;
}
else {
trailer->setNextNode(theNode);
numNodes++;
}
}
}
}
示例8: toString
string SList::toString() const {
stringstream ss;
if (head == NULL) {
ss.str("");
} else {
int i = 1;
for (SLNode* n = head; n != NULL; n = n->getNextNode()) {
ss << n->getContents();
if (i < size)
ss << ",";
i++;
}
}
return ss.str();
}
示例9: toString
string SList::toString () const {
stringstream listStream;
SLNode* current;
current = head;
if (head == NULL){
cout << "" << endl;
} else {
while (current != NULL) {
listStream << current->getContents() << ",";
current = current->getNextNode();
}
}
return(listStream.str().substr(0,listStream.str().length() - 1));
}
示例10: 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;
}
示例11: insert
void SList::insert(int contents) {
if (head == NULL) {
insertHead(contents);
} else {
size++;
SLNode* newNode = new SLNode(contents);
if (head->getContents() > contents){
SLNode* oldHead = head;
head = newNode;
head->setNextNode(oldHead);
oldHead = NULL;
} else {
if (head->getNextNode() == NULL) {
head->setNextNode(newNode);
} else {
SLNode* nodeMark = head->getNextNode();
SLNode* lagMark = NULL;
for (unsigned int i = 0; i < size; i++) {
if (nodeMark->getContents() < contents && nodeMark->getNextNode() != NULL) {
lagMark = nodeMark;
nodeMark = nodeMark->getNextNode();
}
}
if (lagMark == NULL) {
head->setNextNode(newNode);
newNode->setNextNode(nodeMark);
} else if (nodeMark->getNextNode() == NULL) {
nodeMark->setNextNode(newNode);
} else {
lagMark->setNextNode(newNode);
newNode->setNextNode(nodeMark);
}
nodeMark = NULL;
lagMark = NULL;
}
}
newNode = NULL;
}
}