In this lesson, I will show you an iterative program to swap all pairwise nodes of a linked list.

Are we swapping the pairwise data of nodes or the complete node?

We'll we swapping the nodes, as a result the data will get swapped. Swapping only the element does not make any sense.

For example, if the linked list is 1-2-3-4-5-6 then pairwise swapping all nodes will give us the linked list 2-1-4-3-6-5.

If the linked list is 1-2-3-4-5 then pairwise swapping all nodes will give us the linked list 2-1-4-3-5.

Observe the representation above, the address and data of the nodes.

The following program code require the understanding of insertAfter() function and printList() function.

```[code language="C"]
/Pairwise swap all elements of linked list.

#include&amp;lt;stdio.h&amp;gt;
#include&amp;lt;stdlib.h&amp;gt;

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

void printList(struct Node*);
struct Node* insertAfter(struct Node**, int); //returns adress of last node
void pairWiseSwap(struct Node**);

int main()
{
struct Node *endMarker;
endMarker = insertAfter(&amp;amp;endMarker, 3);
endMarker = insertAfter(&amp;amp;endMarker, 4);
endMarker = insertAfter(&amp;amp;endMarker, 5);
endMarker = insertAfter(&amp;amp;endMarker, 6);

return 0;
}

struct Node *t1, *t2, *beforeT1 = NULL;
int count = 0;

//init

while(t1 &amp;amp;&amp;amp; t2){

t1-&amp;gt;next = t2-&amp;gt;next;
t2-&amp;gt;next = t1;

if(count == 0)
else{
beforeT1-&amp;gt;next = t2;
}

beforeT1 = t2;

if(t2-&amp;gt;next == NULL)
t1 = NULL;
else
t1 = t1-&amp;gt;next; //t1 = t1-&amp;gt;next;

if(t1 == NULL)
t2 = NULL;
else
t2 = t1-&amp;gt;next;

count++;
beforeT1 = beforeT1-&amp;gt;next;
}

}

void printList(struct Node* node){
int count=0;
while(node!=NULL){
printf("\t%d", node-&amp;gt;data);
node = node-&amp;gt;next;
count++;
}
printf("\nTotal nodes printed=\t%d\n", count);
}

struct Node* insertAfter(struct Node **node, int data){
if( (*node)==NULL) {
printf("Node Does Not Exists\n");
return NULL;
}
struct Node *new = (struct Node*)malloc(sizeof(struct Node));
new-&amp;gt;data = data;
new-&amp;gt;next = (*node)-&amp;gt;next;
(*node)-&amp;gt;next = new;
return new;
}

[/code]```