我在鏈表中的元素之後插入元素,但我的代碼沒有運行。在雙向鏈表中的元素之後插入
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