cccsiqi47 于 2016.04.19 23:14 提问

#include
#include
struct node{
int data;
node *next;
};
node *create_sort(void)
{
int a;
printf("建立一条有序链表，请输入数据，以-1结束:");
scanf("%d,&a);
while (a!=-1){
p1=new node;
p1->data=a;
scanf("%d,&a);
}
{
const node *p;
printf("链表上各个节点的数据为:\n");
while(p!=NULL){
printf("%d\t",p->data);
p=p->next;
}
printf("\n");
}
{
node *p1,*p2;
printf("链表为空，无节点可删！\n");
return(NULL);
}
delete p1;
printf("删除了一个节点！\n");
}
else{
while(p2->data!=num&&p2->next!=NULL){
p1=p2;
p2=p2->next;
}
if(p2->data==num){
p1->next=p2->next;
delete p2;
printf("删除了一个节点！\n");
}
else printf("%d链表上没找到要删除的节点！\n",num);
}
}
void deletechain(node *h)
{
node *p1;
while(h){
p1=h;
h=h->next;
delete p1;
}
printf("已释放链表的节点空间！\n");
}

{
int n;
node *p;
n=0;
while(p!=NULL){
n=n+1;
p=p->next;
}return(n);
}

{
int j=1;
node *p,*p1;
printf("链表为空，无节点可删！\n");
return(NULL);
}
if(k==1){
delete p;
printf("删除了第一个节点！\n");
}
else{
if(p->next!=NULL)
{
p1=p->next;
p->next=p1->next;
delete p1;
printf("删除了第%d个节点！\n",k);
}
}
}
void main(void)
{
int num;
int k;
printf("输入要删除节点上的序号！\n");
scanf("%d,&num);
printf("输入要删除节点上的整数！\n");
scanf("%d,&num);
printf("输入要插入的整数！\n");
scanf("%d",&num);
}

``````调试错误显示如下：
h:\mydocuments\csq\csq.cpp(12) : error C2001: newline in constant
``````

h:\mydocuments\csq\csq.cpp(13) : error C2143: syntax error : missing ')' before 'while'
h:\mydocuments\csq\csq.cpp(13) : error C2143: syntax error : missing ';' before '{'
h:\mydocuments\csq\csq.cpp(16) : error C2065: 'insert' : undeclared identifier
h:\mydocuments\csq\csq.cpp(16) : error C2440: '=' : cannot convert from 'int' to 'struct node *'
Conversion from integral type to pointer type requires reinterpret_cast, C-style cast or function-style cast
h:\mydocuments\csq\csq.cpp(17) : error C2001: newline in constant
h:\mydocuments\csq\csq.cpp(18) : error C2143: syntax error : missing ')' before '}'
h:\mydocuments\csq\csq.cpp(18) : error C2143: syntax error : missing ';' before '}'
h:\mydocuments\csq\csq.cpp(98) : error C2065: 'find' : undeclared identifier
h:\mydocuments\csq\csq.cpp(98) : error C2440: '=' : cannot convert from 'int' to 'struct node *'
Conversion from integral type to pointer type requires reinterpret_cast, C-style cast or function-style cast
h:\mydocuments\csq\csq.cpp(116) : error C2001: newline in constant
h:\mydocuments\csq\csq.cpp(117) : error C2146: syntax error : missing ')' before identifier 'printf'
h:\mydocuments\csq\csq.cpp(118) : error C2001: newline in constant
h:\mydocuments\csq\csq.cpp(119) : error C2146: syntax error : missing ')' before identifier 'head'
h:\mydocuments\csq\csq.cpp(122) : error C2001: newline in constant
h:\mydocuments\csq\csq.cpp(123) : error C2146: syntax error : missing ')' before identifier 'head'
h:\mydocuments\csq\csq.cpp(127) : error C2440: '=' : cannot convert from 'int' to 'struct node *'
Conversion from integral type to pointer type requires reinterpret_cast, C-style cast or function-style cast

7个回答

qq423399099      2016.04.20 21:00

`````` #include<iostream>
using namespace std;

struct node{
int data;
node *next;
};

{
while(p && k-- > 0)
{
pre = p;
p = p->next;
}
if(p == NULL)
printf("未找到该元素位置\n");
return pre;
}

{
if(p == NULL)//链表为空，插入第一个元素
{
node *p1 = new node;
p1->data = elem;
p1->next = NULL;
}
else
{
while(p)
{
if(p->data > elem || p->next == NULL)//如果找到了要找的位置或者已经到最后的节点了
{
node *p1 = new node;
p1->data = elem;
{
if( p->data > elem)
{
p1->next = p;
}
else
{
p1->next = p->next;
p->next = p1;
}
}
else
{
if(p->data < elem)
{
p->next = p1;
p1->next = NULL;
}
else
{
p1->next = p;
pre->next =p1;
}
}
break;
}
pre = p;
p = p->next;
}
}
}

node *create_sort(void)
{
int a;
printf("建立一条有序链表，请输入数据，以-1结束:");
scanf("%d",&a);
while (a!=-1){
scanf("%d",&a);
}
}
{
const node *p;
printf("链表上各个节点的数据为:\n");
while(p!=NULL){
printf("%d\t",p->data);
p=p->next;
}
printf("\n");
}
{
node *p1,*p2;
printf("链表为空，无节点可删！\n");
return(NULL);
}
delete p1;
printf("删除了一个节点！\n");
}
else{
while(p2->data!=num&&p2->next!=NULL){
p1=p2;
p2=p2->next;
}
if(p2->data==num){
p1->next=p2->next;
delete p2;
printf("删除了一个节点！\n");
}
else printf("%d链表上没找到要删除的节点！\n",num);
}
}
void deletechain(node *h)
{
node *p1;
while(h){
p1=h;
h=h->next;
delete p1;
}
printf("已释放链表的节点空间！\n");
}
{
int n;
node *p;
n=0;
while(p!=NULL){
n=n+1;
p=p->next;
}return(n);
}
{
int j=1;
node *p,*p1;
printf("链表为空，无节点可删！\n");
return(NULL);
}
if(k==1){
delete p;
printf("删除了第一个节点！\n");
}
else{
if(p->next!=NULL)
{
p1=p->next;
p->next=p1->next;
delete p1;
printf("删除了第%d个节点！\n",k);
}

}
}
void main(void)
{
int num;
int k;
printf("输入要删除节点上的序号！\n");
scanf("%d",&k);
printf("输入要删除节点上的整数！\n");
scanf("%d",&num);
printf("输入要插入的整数！\n");
scanf("%d",&num);
}
``````

caozhy      2016.04.19 23:39

scanf("%d,&a);

scanf("%d",&a);

qq_24241339   2016.04.20 01:54

u013544163   2016.04.20 08:56

scanf("%d,&a);

zhudingsuifeng   2016.04.20 10:23

qq423399099      2016.04.20 10:42

find和insert应该在你自己写的文件中有的吧

``````#include<iostream>
using namespace std;
struct node{
int data;
node *next;
};
node *create_sort(void)
{
int a;
printf("建立一条有序链表，请输入数据，以-1结束:");
scanf("%d",&a);
while (a!=-1){
p1=new node;
p1->data=a;
scanf("%d",&a);
}
{
const node *p;
printf("链表上各个节点的数据为:\n");
while(p!=NULL){
printf("%d\t",p->data);
p=p->next;
}
printf("\n");
}
{
node *p1,*p2;
printf("链表为空，无节点可删！\n");
return(NULL);
}
delete p1;
printf("删除了一个节点！\n");
}
else{
while(p2->data!=num&&p2->next!=NULL){
p1=p2;
p2=p2->next;
}
if(p2->data==num){
p1->next=p2->next;
delete p2;
printf("删除了一个节点！\n");
}
else printf("%d链表上没找到要删除的节点！\n",num);
}
}
void deletechain(node *h)
{
node *p1;
while(h){
p1=h;
h=h->next;
delete p1;
}
printf("已释放链表的节点空间！\n");
}
{
int n;
node *p;
n=0;
while(p!=NULL){
n=n+1;
p=p->next;
}return(n);
}
{
int j=1;
node *p,*p1;
printf("链表为空，无节点可删！\n");
return(NULL);
}
if(k==1){
delete p;
printf("删除了第一个节点！\n");
}
else{
if(p->next!=NULL)
{
p1=p->next;
p->next=p1->next;
delete p1;
printf("删除了第%d个节点！\n",k);
}
}
}
void main(void)
{
int num;
int k;
printf("输入要删除节点上的序号！\n");
scanf("%d",&num);
printf("输入要删除节点上的整数！\n");
scanf("%d",&num);
printf("输入要插入的整数！\n");
scanf("%d",&num);