error C4700: 使用了未初始化的局部变量“p”
#include<stdio.h>#include<iostream>usingnamespacestd;#defineerror0#defineok1#defineov...
#include<stdio.h>
#include<iostream>
using namespace std;
#define error 0
#define ok 1
#define overflow -1
typedef int Status;
typedef struct LNode{
int data;
struct LNode *next;
}LNode, *LinkList;
Status InitList_L(LinkList &L){
L = new LNode;
if (!L) exit(overflow);
L->next = NULL;
return ok;
}
Status charu(LinkList &L, int i){
L->data = i;
for (i = 0; i < L->data; i++){
LNode* p; //error C4700: 使用了未初始化的局部变量“p” 怎么解决 求教
cin >> p->data;
p->next = L->next;
L->next = p;
}
return ok;
}
void inverse(LinkList &L) {
// 逆置带头结点的单链表 L
LNode*p;
p = L->next; L->next = NULL;
while (p) {
LNode*q;
q = p->next; // q指向*p的后继
p->next = L->next;
L->next = p; // *p插入在头结点之后
p = q;
delete q;
}
}
void print(LinkList L){
LNode*p;
p = L->next;
while(p){
cout << p->data<<endl;
p = p->next;
}
}
int main(){
LinkList L; int i;
cout << "请输入数据" << endl;
cin >> i;
charu(L,i);
print(L);
inverse(L);
print(L);
} 展开
#include<iostream>
using namespace std;
#define error 0
#define ok 1
#define overflow -1
typedef int Status;
typedef struct LNode{
int data;
struct LNode *next;
}LNode, *LinkList;
Status InitList_L(LinkList &L){
L = new LNode;
if (!L) exit(overflow);
L->next = NULL;
return ok;
}
Status charu(LinkList &L, int i){
L->data = i;
for (i = 0; i < L->data; i++){
LNode* p; //error C4700: 使用了未初始化的局部变量“p” 怎么解决 求教
cin >> p->data;
p->next = L->next;
L->next = p;
}
return ok;
}
void inverse(LinkList &L) {
// 逆置带头结点的单链表 L
LNode*p;
p = L->next; L->next = NULL;
while (p) {
LNode*q;
q = p->next; // q指向*p的后继
p->next = L->next;
L->next = p; // *p插入在头结点之后
p = q;
delete q;
}
}
void print(LinkList L){
LNode*p;
p = L->next;
while(p){
cout << p->data<<endl;
p = p->next;
}
}
int main(){
LinkList L; int i;
cout << "请输入数据" << endl;
cin >> i;
charu(L,i);
print(L);
inverse(L);
print(L);
} 展开
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询