//不删掉Delete语句就报错,删掉之后能输出预期值,为什么
//user 为自定义类
#include<iostream.h>
#include<fstream.h>
#include<string.h>
#include"6.h"
BOOK *book;
user *USER;
int main()
{
user *p,*h;
fstream ip("c:\\user_information.txt",ios::in);
if(ip.eof()==0)
{p=new user;
h=p;}
else return 0;
while(1)
{
ip>>p->user_name;
if(ip.eof()!=0)break;
p->unext=new user;
p=p->unext;
}
p->unext=NULL;
p=h;
ip.close();
while(p)
{
cout<<p->user_name;
p=p->unext;
}
delete[]h;
return 0;
}
以下是我自己写的程序:有插入删除和输出链表元素功能,希望采纳#include<stdio.h>#include<stdlib.h>struct node;int num=0;node* createlist(node *p) printf("单链表创建成功!!\n"); printf("\n"); return p;}void output(node *p) printf("\n");}node* search(node *p,int k)node* insert(node *p,node *q)node* del(node *p,node *q)int main() printf("\n"); q=search(p,k); printf("插入位置原来的元素为:%d\n",q->DATA); p=insert(p,q); output(p); printf("\n"); while(1) printf("\n"); q=search(p,k); printf("删除位置原来的元素为:%d\n",q->DATA); p=del(p,q); output(p); printf("\n"); printf("------试验完成,谢谢使用------\n"); printf("如果有疑问请加本人QQ 510685263\n"); printf("----That's all thank you------\n"); printf("\n"); return 0;}
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息