链表问题
Linked List Problems
所以我创建了一个带有 Struct 节点的类Linked_List,但似乎有一些我不知道如何修复的错误,这是代码:
#include <iostream>
using namespace std;
struct node{
int info;
node *link;
};
class Linked_List{
private :
int count;
node *first;
node *last;
node *current;
public:
Linked_List() {
count=0;
first=NULL;
last=NULL;
}
void Initialize_List(){
cout<<"Enter Number OF Nodes"<<endl;
cin>>count;
first=last=current=new node;
for(int i =0;i<count;i++){
cin>>current->info;
last->link=current;
last=current;
current=new node;}
last->link=NULL;
}
bool Is_Empty(){
if(first==NULL)
{
cout<<"The List Is Empty"<<endl;
return true;
}
else{
cout<<"The List Is Not Empty"<<endl;
return false;}
}
bool Search(int x){
for(current=first;current!=NULL;current=current->link){
if (current->info==x)
return true;
else return false;} }
void Insert_First(int x){
count++;
current=new node;
current->info=x;
current->link=first;
first=current;
if(last==NULL){
last=current;
last->link=NULL;}}
void Insert_Last(int x){
count++;
current=new node;
current->info=x;
last->link=current;
last=current;
last->link=NULL;
if(first==NULL)
first=current;
}
void Delete_First(){
if(!Is_Empty())
{ node *p;
p=first;
first=first->link;
delete p;
count --;
if(count==0)
first=last=Null;}
}
void Delete_Last(){
node *p;
if(count<=1){
count=0;
p=last;
delete p;
last=first=NULL;}
else {
p=first;
for(p=first;P->link!=last;p=p->link){
last=p;
p=p->link;
delete p;
last->link=NULL;
count--;}}
}
};
void main (){
//nothing done here yet
}
编译器给了我这些错误(它在函数上给了我这个错误Delete_First):
1-'Null' : 未声明的标识符
2-"=":无法从"int"转换为"结构节点*"
两个错误都打开了(第一个=最后一个=空;})线
非常感谢您的帮助
first=last=Null;
是一个错误,因为Null
应该NULL
(全大写)。无需声明/定义NULL
,它已经在您的实现头文件中(在您的情况下,<iostream>
)。
实际上,您会发现NULL
实际上只是一个扩展到0
(或(void*)0
)的宏,即#define NULL (void*)0
。
让我知道这是否可以修复这两个错误。
相关文章:
- 链表指针问题
- 我对数据结构、双向链表有一些问题
- 在解决链表问题时创建一个额外的节点是一个好习惯吗?
- Sinlge 链表,C++,删除所有和搜索功能的问题
- C++ 从链表中删除项目时出现问题
- 如何修复我的链表读数不一致的问题?
- C++中链表实现的问题
- 双向链表问题 - 包含项目但不显示
- 嵌套的类成员变量不可访问.链表设置.V、下一个和新的问题
- 在链表中的某个点插入时出现问题,C++中的继承函数
- cpp 中的以下链表程序有什么问题?
- 单个链表,节点插入最低到最高节点值的问题
- 我在让我的代码输出整个链表时遇到问题.它只是输出我修改过的一些文本文件,而不是整个东西
- 双向链表问题(特别是复制构造函数和删除函数)
- 我在双链表上的此打印功能时遇到问题
- 我在显示链表时遇到问题
- 尝试在链表程序的末尾进行更简单的插入.小问题需要帮助
- 节点和链表问题
- c++理解问题-链表和堆栈
- C++语法问题(链表)