#include <stdio.h>
#include <stdlib.h>
#define length k
typedef int ListData;
struct node
{
node *link
ListData k;
};
int Build(node *first)
{
first -> link == NULL;
node *q = first;
int m,a;
printf ("请输入链表的长度\n");
scanf ("%d",&m);
printf ("请输入链表的元素\n");
for (int i=0;i<m;i++)
{
scanf ("%d",&a);
node *newnode = new node;
newnode -> k = a;
first ->length ++;
newnode -> link = q -> link;
q -> link =newnode;
q = q -> link;
}
return 1;
}
int place_move (node *p,node *pr,node *first)
{
int n;
printf ("请任意输入一个坐标位置\n");
scanf ("%d",&n);
if (n> first -> length)
{
printf ("该链表中没有所找的位置\n");
return 0;
}
else
{
for ( int i=0;i<n;i++)
{
pr = pr -> link;
p = pr -> link;
}
}
node *q;
node *L=first -> link;
first ->link =NULL;
for (int i=0;i<n;i++)
{
q=L;
L = L -> link;
q -> link =first -> link;
first -> link = q;
}
int m;
printf ("请输入p往后移动的结点数\n");
scanf ("%d",&m);
if (m > first -> length -n)
{
for (int i=0;i<(first -> length -n);i++)
{
node *q = pr;
pr=p;
p= p -> link;
pr -> link = NULL;
pr -> link =q;
}
for (int i=0; i<first -> length;i++)
{
printf ("%d",pr -> k);
printf (" ");
pr = pr -> link; }
p = NULL;
}
for (int i=0; i<first -> length;i++)
{
printf ("%d",pr -> k);
printf (" ");
pr = pr -> link;
}
p = NULL;
printf ("p已经移出链表\n");
}
else
{
for (int i=0;i<m;i++)
{
node *q = pr;
pr=p;
p= p -> link;
pr -> link = NULL;
pr -> link =q;
}
for (int i=0; i<m;i++)
{
printf ("%d",pr -> k);
printf (" ");
pr = pr -> link;
}
}
return 1;
}
int main ()
{
node *first=new node;
first -> length=0;
node *p;
node *pr= first;
Build (first);
int n;
place_move (p,pr,first);
system ("pause");
return 0;
}