How to implement swapping of structs for the insertion sorting algorithm in C
c, insertion-sort, struct
Solution
You can swap `struct`s the same way that you swap integers:
wordType tmp;
wordType a = {.word="hello", .count=5};
wordType b = {.word="world", .count=11};
tmp = a;
a = b;
b = tmp;
Demo on ideone.
Problem
I have a working insertion sort algorithm that sorts integers stored in an array. In a different program I have created a struct with words and a count. I need to sort structs stored in an array alphabetically using the same insertion sort. I understand how to compare them, however I cannot find a way to swap them. Ideas? ``` typedef struct { char * word; int count; } wordType; ```