这是一个关于 数据结构链表结点指针赋值问题


#include<iostream>
#include<conio.h>
#include<string.h>
#define OK 1
#define MAXSIZE 100
#define ERROR -1
using namespace std;
typedef  int Status;
#define OK 1
typedef  struct  
{
char name[5];
float price;    
}Book;
typedef  Book ElemType;
typedef  struct  LNode 
{
Book data;
LNode *next;

}LNode,*List;

Status InitList(List &L)
{
  L=new LNode();
  /*if(!B)
      exit(-1);
  else
  */
    L->next=NULL;
  return OK;
}
Status GetElem(int i,List L,ElemType &e)
{

List P=L->next; int j=1;
while(P&&j<1)
{


P=P->next;
++j;
}
if(!P||j<i)
return ERROR;
e=P->data;

return OK;
}
Status QianCha(List Head,List L,List  shou)
{
if(Head->next=NULL)
{
    Head->next=L;
    L->next=shou;

}
else
{
   Head->next=L->next;
   L->next=NULL;
}   
   return 0;
}
void Q(List &L,int n)
{
L=new LNode();
L->next=NULL;
for(int i=0;i<n;i++)
{
LNode  *p=new LNode();
cin>>(p->data.price);
p->next=L->next;
L->next=p;
}

}

int main()
{

Book e;
/*
注释代码不用看!
LNode *tou=NULL;

List LL=NULL;
List MM=NULL;
InitList(tou);
List BBB=NULL;
InitList(BBB);
InitList(LL);
InitList(MM);
QianCha(tou,BBB,LL);
QianCha(tou,,BBB);
GetElem(1,tou,e);
*/
List haha;
Q(haha,4);

cout<<e.price;
getch();


return 0;
}

这是我写的代码,想测试 用前插法生成单链表,在单步调试过程中,
出现这个界面

图片说明

生成了结点L空间,给L的属性next指针赋值,调试工具中不能看到NULL(即000000地址)为什么呢?

因为L->next是NULL,你自己摄制的,所以没有办法显示,这个很正常啊。

你可以试试vs2010的环境,看着更清楚
图片说明

代码我给完善了下:

// Q1049361.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"


#include<iostream>
#include<conio.h>
#include<string.h>
#define OK 1
#define MAXSIZE 100
#define ERROR -1
using namespace std;
typedef  int Status;
#define OK 1
typedef  struct  
{
char name[5];
float price;    
}Book;
typedef  Book ElemType;
typedef  struct  LNode 
{
Book data;
LNode *next;

}LNode,*List;

Status InitList(List &L)
{
  L=new LNode();
  /*if(!B)
      exit(-1);
  else
  */
    L->next=NULL;
  return OK;
}
Status GetElem(int i,List L,ElemType &e)
{

List P=L->next; int j=1;
while(P&&j<1)
{


P=P->next;
++j;
}
if(!P||j<i)
return ERROR;
e=P->data;

return OK;
}
Status QianCha(List Head,List L,List  shou)
{
if(Head->next=NULL)
{
    Head->next=L;
    L->next=shou;

}
else
{
   Head->next=L->next;
   L->next=NULL;
}   
   return 0;
}
void Q(List &L,int n)
{
L=new LNode();
L->next=NULL;
for(int i=0;i<n;i++)
{
LNode  *p=new LNode();
cout << "name?";
cin>>(p->data.name);
cout << "price?";
cin>>(p->data.price);
cout << endl;
p->next=L->next;
L->next=p;
}

}

int main()
{

Book e;
/*
注释代码不用看!
LNode *tou=NULL;

List LL=NULL;
List MM=NULL;
InitList(tou);
List BBB=NULL;
InitList(BBB);
InitList(LL);
InitList(MM);
QianCha(tou,BBB,LL);
QianCha(tou,,BBB);
GetElem(1,tou,e);
*/
List haha;
Q(haha,4);
haha = haha->next;
while (haha)
{
    e = haha->data;
    cout<<e.name << "," << e.price<<endl;
    haha = haha->next;
}
getch();


return 0;
}

name?a
price?1

name?b
price?2

name?c
price?3

name?d
price?4

d,4
c,3
b,2
a,1