【发布时间】:2014-03-10 19:23:35
【问题描述】:
我正在尝试为课堂做一个实验室,尽管有教授的讲座和随附的阅读材料,但我在搞清楚语法时遇到了问题。如果有人可以帮助其中一项功能,我觉得我可以弄清楚其余的。
这是标题
#pragma once
#include <string>
using namespace std;
struct ListNode
{
public:
ListNode( const string& theString, ListNode* pNext = NULL )
{
word = theString;
pNextNode = pNext;
}
string word;
ListNode* pNextNode;
};
//add a node (pNode) at the head of the list.
//return a pointer to the head node
ListNode* addFront( ListNode* pHead, ListNode* pNode );
//add a node (pNode) at the tail of the list.
//return a pointer to the head node
ListNode* addEnd( ListNode* pHead, ListNode* pNode );
//remove (and cleanup after) the node at the head of the LinkedList (pHead)
//return a pointer to the head node
ListNode* removeFront( ListNode* pHead );
//remove (and cleanup after) the node at the tail of the LinkedList (pHead)
//return a pointer to the head node
ListNode* removeEnd( ListNode* pHead );
//traverse the LinkedList (pHead) and delete all nodes
//return a pointer to the head node
ListNode* removeAllNodes( ListNode* pHead );
//traverse the LinkedList (pHead) and write out all the words in the list
//separated by a space
void printNodeReport( ListNode* pHead, ostream& out );
这是我需要在其中实现存根的 cpp
#include "LinkedList.h"
#include <string>
#include <sstream>
//add a node (pNode) at the head of the list.
//return a pointer to the head node
ListNode* addFront( ListNode* pHead, ListNode* pNode )
{
//stub
return pHead;
}
//add a node (pNode) at the tail of the list.
//return a pointer to the head node
ListNode* addEnd( ListNode* pHead, ListNode* pNode )
{
//stub
return pHead;
}
//remove (and cleanup after) the node at the head of the LinkedList (pHead)
//return a pointer to the head node
ListNode* removeFront( ListNode* pHead )
{
//stub
return pHead;
}
//remove (and cleanup after) the node at the tail of the LinkedList (pHead)
//return a pointer to the head node
ListNode* removeEnd( ListNode* pHead )
{
//stub
return pHead;
}
//traverse the LinkedList (pHead) and delete all nodes
//return a pointer to the head node
ListNode* removeAllNodes( ListNode* pHead )
{
//stub
return pHead;
}
//traverse the LinkedList (pHead) and write out all the words in the list
//separated by a space
void printNodeReport( ListNode* pHead, ostream& out )
{
out << "Here's the list: ";
ListNode* pCurr = pHead;
while( pCurr != NULL )
{
out << pCurr->word << " ";
pCurr = pCurr->pNextNode;
}
out << "EOL \n";
}
【问题讨论】:
-
哪个函数?什么语法?具体...
-
哇,按照这个速度,他们可能会在 20 年内向学生教授当前的 C++ 标准。
-
查看stackoverflow.com/questions/397895/…,Johannes Schaub 的答案
标签: c++ linked-list