Swap med pointer til struct
Hej, jeg skal bruge hjælp.Jeg vil lave en swap af 2 elementer i en dobbelt hægtet liste.
Sådan at left og right pointerne bliver ombyttet.
Men det virker ikke, bør måske bruge &pointer eller **pointer ?!!!
Det lykkedes ikke for mig, hvad gør jeg forkert ?
void main()
{
int inputarray[STR_AF_LISTE] = {45, 32, 2, 36};
struct node datanode[STR_AF_LISTE];
struct node *p1 = NULL;
struct node *p2 = NULL;
.
.
.
p1 = pointer_firstnode->pointer_right->pointer_right;
p2 = pointer_firstnode->pointer_right;
swap_(p1, p2);
/* har også prøvet swap_(&p1, &p2); men det virker ikke */
}
void swap_1( struct node *pointer1, struct node *pointer2)
{
struct node *ptemp;
ptemp->pointer_left = pointer1->pointer_left;
ptemp->pointer_right = pointer1->pointer_right;
pointer1->pointer_left = pointer2->pointer_left;
pointer1->pointer_right = pointer2->pointer_right;
pointer2->pointer_left = ptemp->pointer_left;
pointer2->pointer_right = ptemp->pointer_right;
}