笔记本1
链表反转 数组解法部分通过 (小白 欢迎大家指正错误)
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#define M 100000
typedef struct node{
char front[M],behind[M];
int element;
}Node;
void Sorted_link(char first[M],Node a[M],int N)
{
Node temp;
for(int i=0;i<N;i++)
{
if(strcmp(a[i].front,first)==0)
{
temp=a[0];
a[0]=a[i];
a[i]=temp;
}
}
for(int i=0;i<N-1;i++)
{
for(int j=i+1;j<N;j++)
{
if(strcmp(a[i].behind,a[j].front)==0)
{
temp=a[i+1];
a[i+1]=a[j];
a[j]=temp;
break;
}
}
}
}
void Reversed_link(Node a[M],int N,int K)
{
int quo,count;
Node temp;
quo=N/K;
for(int i=0;i<quo;i++)
{
count=0;
for(int j=i*K,k=(i+1)*K-1;count<K/2;j++,k--)
{
temp=a[j];
a[j]=a[k];
a[k]=temp;
count++;
}
}
}
void Sorted_Reversed(Node a[M],int N)
{
char temp1[M]="-1";
for(int i=0;i<N-1;i++)
{
//strcpy(temp1,a[i+1].first);
strcpy(a[i].behind,a[i+1].front);
}
strcpy(a[N-1].behind,temp1);
}
int main()
{
char first[M];
int N,K;
int quo;
scanf("%s %d %d",first,&N,&K);
Node a[N];
for(int i=0;i<N;i++)
{
scanf("%s %d %s",a[i].front,&a[i].element,a[i].behind);
}
Sorted_link(first,a,N);
Reversed_link(a,N,K);
Sorted_Reversed(a,N);
for(int j=0;j<N;j++)
{
printf("%s %d %s",a[j].front,a[j].element,a[j].behind);
if(j!=N-1)
{
printf("\n");
}
}
}