c++ XCODE需要初学者帮助使用
C++ XCODE need help Beginner Using
大家好,我写了下面的代码
除非我得到一个错误,当我在xcode中编译它时,任何帮助将是最伟大的
#include <iostream.h>
class node
{
public:
int value; //value stored in the node
node *next; //pointer to next node
node *prev; //pointer to previous node
};
class dlist
{
public:
node *front; //pointer to front of list
node *back; //pointer to back of list
dlist()
{
front=NULL;
back=NULL;
}
void insertFront(int value);
void insertBack(int value);
void removeFront();
void removeBack();
void insertBefore(int value,node *nodeB);
void insertAfter(int value,node *nodeA);
void removeBefore(node *nodeB);
void removeAfter(node *nodeA);
void removeNode(node *newNode);
void printDListFront();
void printDListBack();
};
//insert a node before nodeB
void dlist::insertBefore(int value,node *nodeB)
{
node *newNode;
newNode=new node();
newNode->prev=nodeB->prev;
newNode->next =nodeB;
newNode->value =value;
if(nodeB->prev==NULL)
{
this->front=newNode;
}
nodeB->prev=newNode;
}
//insert a node before the front node
void dlist::insertFront (int value)
{
node *newNode;
if(this->front==NULL)
{
newNode=new node();
this->front=newNode;
this->back =newNode;
newNode->prev=NULL;
newNode->next=NULL;
newNode->value=value;
}
else
{
insertBefore(value,this->front );
}
}
//insert a node after nodeB
void dlist::insertAfter(int value,node *nodeB)
{
node *newNode;
newNode=new node();
newNode->next= nodeB->next ;
newNode->prev =nodeB;
newNode->value =value;
if(nodeB->next==NULL)
{
cout<<"n "<< endl;
this->back =newNode;
}
nodeB->next=newNode;
cout<<"2"<<endl;
}
//insert a node after the last node
void dlist::insertBack (int value)
{
if(this->back==NULL)
{
cout<<"insert at back";
insertFront(value);
}
else
{
cout<<"insert at back";
insertAfter(value,this->back );
}
}
//remove the front node
void dlist::removeFront ()
{
removeNode(this->front);
}
//remove a back node
void dlist::removeBack ()
{
removeNode(this->back);
}
//remove before a node
void dlist::removeBefore(node *nodeB)
{
if(nodeB->prev==this->front)
{
this->front=nodeB;
this->front->prev=NULL;
}
else
{
removeNode(nodeB->prev);
}
}
//remove after a node
void dlist::removeAfter(node *nodeA)
{
if(nodeA->next==this->back)
{
this->back=nodeA;
this->back->next=NULL;
}
else
{
removeNode(nodeA->next);
}
}
//remove a perticular node
void dlist::removeNode(node *nodeToRemove)
{
if(nodeToRemove==this->front)
{
this->front=this->front->next;
this->front->prev=NULL;
}
else if (nodeToRemove==this->back)
{
this->back=this->back->prev;
this->back->next=NULL ;
}
else
{
nodeToRemove->prev->next=nodeToRemove->next;
nodeToRemove->next->prev=nodeToRemove->prev;
}
}
//Print the list from front
void dlist::printDListFront()
{
node* curr2;
curr2= this->front;
cout<<"n-----n";
cout<<"Queuen";
cout<<"-----n";
//cout<<"size:"<<getQueueSize()<<endl;
while(curr2!=NULL)
{
cout<<" |"<<curr2->value<<"|";
curr2=curr2->next;
}
cout<<endl;
}// print the Double Linked List from front
// print the Double Linked List from backwards
void dlist::printDListBack()
{
node* curr2;
curr2= this->back;
cout<<"n-----n";
cout<<"Queuen";
cout<<"-----n";
//cout<<"size:"<<getQueueSize()<<endl;
while(curr2!=NULL)
{
cout<<" |"<<curr2->value<<"|";
curr2=curr2->prev;
}
cout<<endl;
}// print the Double Linked List from back
void main()
{
dlist *st ;
st= new dlist();
st->insertBack(8);
st->printDListFront ();
st->insertBack(5);
st->printDListFront ();
st->insertBack(6);
st->printDListFront ();
st->insertFront(1) ;
st->printDListFront ();
st->insertFront(3) ;
st->printDListFront ();
st->insertBack(7);
st->printDListFront ();
st->removeFront();
st->printDListFront ();
st->removeBack();
st->printDListFront ();
}
我得到的错误是MAIN必须返回"int"
出自ISO/IEC 14882:2003(E) - 3.6.1
实现不能预先定义main函数。此函数不得重载。它的返回类型必须是int,否则它的类型是实现定义的。所有实现都应该允许以下两种main定义:
int main() { /* ... */ } and
int main(int argc, char* argv[]) { /* ... */ }
也不需要在标准头文件中包含.h
。
#include <iostream> // is sufficient
void main
不标准。
必须返回int。
int main()
较好
请参阅本文以获得更多解释:http://www.parashift.com/c++-faq-lite/newbie.html#faq-29.3
相关文章:
- 需要帮助设置在C++中使用的Potrace
- 在指针的帮助下,文本文件中单词的频率
- C++错误消息*成员参考.**初学者*
- 计算每个节点的树高,帮助我解释这个代码解决方案
- 如何在Qbutton的帮助下更改Q对话框的宽度
- 需要帮助将结构数组传递给函数
- 嵌套for循环C++的问题(初学者)
- C++需要帮助从用户那里获得一个整数,并确保它在另外两个整数之间
- 我是 C++ 的初学者,我想知道如何在 2D 矢量中获取重复值
- 需要帮助在 c++ 中将字符串转换为字符 ----错误 "const char *" 类型的值不能用于初始化 "char" 类型的实体
- 有人可以帮助我处理正则表达式吗?
- C++调用具有 *this 属性的单个帮助程序函数
- C++:需要帮助了解运算符重载错误
- 需要以下代码的帮助,下面的代码有什么问题
- 初学者需要帮助对数组进行排序和计算
- C 投票计划帮助(初学者)
- C++初学者.帮助将结构传递给函数.
- 初学者帮助:用sum打印Table
- 初学者c++帮助:if语句中的if语句
- c++ XCODE需要初学者帮助使用