我在链表中的元素之后插入元素,但我的代码没有运行。在双向链表中的元素之后插入
typedef struct Node
{
int info;
struct Node *next;
struct Node *prev;
}node;
node *head;
// w-the element to be inserted & z-the position after which it has to inserted
void insertpos(int w,int z)
{
int i;
node *ptr=head;
node *ptr1;
for(i=1;i<=z-1;i++)
{
ptr=ptr->next;
}
ptr1=(node*)malloc(sizeof(node));
ptr1->info=w;
ptr->next=ptr1;
((ptr->next)->next)->prev=ptr1;
}
它是C++不是C – JerryGoyal 2015-03-19 10:56:25
@杰里它是C – Newbie786 2015-03-19 10:58:09
用C不必PTR1 =(节点*)malloc的(的sizeof(节点));没有结构。 – JerryGoyal 2015-03-19 10:59:24