кажется, вы забыли оператор сравнения.
измените
if(t2->info=t2->link->info)
на
if(t2->info >= t2->link->info)
Вот полный рабочий код:
#include "stdio.h"
struct node {
int info;
struct node* link;
};
struct node* START = NULL;
void sort(struct node* head,size_t s)
{
//bubble sorting using temporary variable in linked list
int t;
struct node* t1, * t2;
while(s)
{
t1 = head;
t2 = t1->link;
while (t1 != NULL && t2 != NULL)
{
if (t1->info >= t2->info)
{
t = t1->info;
t1->info = t2->info;//info contains data
t2->info = t;//link contains the address of each node or link (next)
}
t1 = t1->link;
t2 = t2->link;
}
--s;
}
}
int main()
{
// Ex > input(5 the size of list) > 9 8 7 5 3 output > 3 5 7 8 9
struct node n1, n2, n3, n4, n5;
struct node* head = &n1;
n1.info = 9;
n1.link = &n2;
n2.info = 8;
n2.link = &n3;
n3.info = 7;
n3.link = &n4;
n4.info = 5;
n4.link = &n5;
n5.info = 3;
n5.link = NULL;
while (head)
{
printf("%d ", head->info);
head = head->link;
}
printf("\n");
head = &n1;
sort(head,5);
while (head)
{
printf("%d ", head->info);
head = head->link;
}
}