Менять местами элементы динамического списка
Нужно поменять местами второй и третий элемент списка. Программа уже меняет первый и последний. Нужна помощь.
#define _CRT_NONSTDC_NO_WARNINGS
#include <conio.h>
#include <stdio.h>
#include <stdlib.h>
#include <locale.h>
#include <Windows.h>
#include <string.h>
typedef struct {
char name[10];
int V, power;
char country[20];
}struc;
typedef struct Node {
struc A;
struct Node* next;
}Node;
Node* create(struc x);
void back(Node** p, struc x);
void prin(Node* p);
void main()
{
SetConsoleCP(1251);
SetConsoleOutputCP(1251);
int A = 1, i = 1;
Node* p = 0;
struc x, y;
Node* head = 0;
while (A != 0)
{
printf("Мотоцикл №%d\n", i);
printf("Введите название %d-го мотоцикла: ", i);
scanf("%s", &x.name);
if (x.name[0] == '*') break;
printf("Введите объем двигателя для %d-го мотоцикла: ", i);
scanf("%d", &x.V);
printf("Введите лошадиные силы для %d-го мотоцикла: ", i);
scanf("%d", &x.power);
printf("Введите страну изготовителя %d-го мотоцикла: ", i);
scanf("%s", &x.country);
printf("\n");
if (A == 1)
{
p = create(x);
head = p;
A += 1;
}
else back(&p, x);
i++;
}
prin(p);
y = p->A;
while (p != NULL) {
if (p->next == NULL) {
x = p->A;
p->A = y;
}
p = p->next;
}
p = head;
p->A = x;
prin(p);
}
Node* create(struc x) {
Node* t = (Node*)malloc(sizeof(Node));
t->A = x;
t->next = NULL;
return t;
}
void back(Node** p, struc x) {
Node* NEWe = create(x);
Node* tpm = *p;
while (tpm->next != NULL) {
tpm = tpm->next;
}
tpm->next = NEWe;
}
void prin(Node* p) {
int i = 1;
printf("+---------------------------------------------------------+\n"
"| | | характеристики | |\n"
"| № | Название |----------+---------| страна |\n"
"| | | обьём | л.с | |\n"
"+---+---------------+----------+---------+----------------+\n");
while (p != NULL) {
printf("| %-2d| %-14s| %-9d| %-8d| %-15s|\n", i, p->A.name, p->A.V, p->A.power, p->A.country);
printf("+---------------------------------------------------------+\n");
p = p->next;
i++;
}
getch();
}```