error C2440: 'initializing' : cannot convert from 'void *' to 'struct list *'是什么错误?
代码如下:#include<stdio.h>#include<stdlib.h>#include<malloc.h>#include<conio.h>structlist...
代码如下:
#include<stdio.h>
#include<stdlib.h>
#include<malloc.h>
#include<conio.h>
struct list{
int data;
struct list *next;
struct list *pre;
};
typedef struct list node;
typedef node *link;
link front=NULL,rear,ptr,head=NULL;
link push(int item){
link newnode=malloc(sizeof(newnode));
//z * x = malloc(sizeof(z));
//z * x =(z*) malloc(sizeof(z)); //注意malloc的写法
newnode->data=item;
if(head==NULL)
{
head=newnode;
head->next=NULL;
head->pre=NULL;
rear=head;
}
else
{
rear->next=newnode;
newnode->pre=rear;
newnode->next=NULL;
rear=newnode;
}
return head;
}
void makenull(){
front=NULL;
rear=NULL;
}
empty(){
if(front==NULL)
return 1;
else
return 0;
}
int tops(){
if(empty())
return NULL;
else
return rear->data;
}
void pop(){
if(empty())
printf("stack is empty!\n");
else
rear=rear->pre;
}
void display(link l){
link p;
p=l;
while(p!=NULL){
printf("%d->",p->data);
p=p->next;
}
}
void main(){
int n,i;
printf("input your first data!\n");
scanf("%d",&n);
front=push(n);
/*another data*/
for(i=0;i<3;i++)
{
printf("input:\n");
scanf("%d",&n);
push(n);
}
ptr=front;
display(ptr);
printf("\n Please enter any key to pop");
getch();
pop();
ptr=front;
display(ptr);
getch();
} 展开
#include<stdio.h>
#include<stdlib.h>
#include<malloc.h>
#include<conio.h>
struct list{
int data;
struct list *next;
struct list *pre;
};
typedef struct list node;
typedef node *link;
link front=NULL,rear,ptr,head=NULL;
link push(int item){
link newnode=malloc(sizeof(newnode));
//z * x = malloc(sizeof(z));
//z * x =(z*) malloc(sizeof(z)); //注意malloc的写法
newnode->data=item;
if(head==NULL)
{
head=newnode;
head->next=NULL;
head->pre=NULL;
rear=head;
}
else
{
rear->next=newnode;
newnode->pre=rear;
newnode->next=NULL;
rear=newnode;
}
return head;
}
void makenull(){
front=NULL;
rear=NULL;
}
empty(){
if(front==NULL)
return 1;
else
return 0;
}
int tops(){
if(empty())
return NULL;
else
return rear->data;
}
void pop(){
if(empty())
printf("stack is empty!\n");
else
rear=rear->pre;
}
void display(link l){
link p;
p=l;
while(p!=NULL){
printf("%d->",p->data);
p=p->next;
}
}
void main(){
int n,i;
printf("input your first data!\n");
scanf("%d",&n);
front=push(n);
/*another data*/
for(i=0;i<3;i++)
{
printf("input:\n");
scanf("%d",&n);
push(n);
}
ptr=front;
display(ptr);
printf("\n Please enter any key to pop");
getch();
pop();
ptr=front;
display(ptr);
getch();
} 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询