#include<stdio.h>
#include<malloc.h>
#include<stdlib.h>
typedef struct Node {
int data;
struct Node* pNext;
}NODE, * PNODE;
PNODE create_list();
int length_list(PNODE pHead);
void delete_s(PNODE m);
void show(PNODE head);
PNODE creLNodePoint(PNODE head, int n);
int main(void)
{
int val, pos;
PNODE head=NULL;
PNODE head1=(PNODE)malloc(sizeof(NODE));
head = create_list();
PNODE m = head->pNext->pNext;
int len = length_list(head);
show(head);
printf("\n");
PNODE s=creLNodePoint(head,3);
delete_s(s);
show(head);
return 0;
}
PNODE create_list()
{
PNODE head = NULL;
PNODE rear = NULL;
PNODE p;
int x;
scanf("%d", &x);
while (x != -1) {
p = (PNODE)malloc(sizeof(NODE));
p->data = x;
if (head == NULL) {
head = p;
rear = p;
p->pNext = NULL;
}
else {
rear->pNext = p;
rear = p;
}
scanf("%d", &x);
}
rear->pNext = head;
return head;
}
void show(PNODE head){
PNODE r=head;
while(r->pNext!=head){
printf("%d",r->data);
r=r->pNext;
}
printf("%d",r->data);
}
void delete_s(PNODE m) {
PNODE s = m;
PNODE pre = s;
while (s->pNext != m) {
pre = s;
s = s->pNext;
}
pre->pNext = m;
free(s);
}
PNODE creLNodePoint(PNODE head, int n)
{
Node *s = head;
while (n--)
{
s = s->pNext;
}
return s;
}