![](https://images2017.cnblogs.com/blog/891120/201711/891120-20171104184837654-470503473.png)
#include <bits/stdc++.h>
using namespace std;
typedef struct LNode
{
int data;
struct LNode *next;
} LNode,*LinkList;
LinkList CreateLinkList(int n)
{
LinkList L = (LinkList )malloc(sizeof(LNode));
LinkList last = (LinkList)malloc(sizeof(LNode));
L->next = NULL;
last = L;
int num = 1;
while (num <= n)
{
LinkList newnode = (LinkList ) malloc(sizeof(LNode));
newnode->data = num;
last->next = newnode;
newnode->next = NULL;
last = newnode;
num++;
}
return L;
}
void DeleteByPos(LinkList &L,int pos)/// 注意:删除元素时候找的是要删除的前一个指针
{
LinkList index = L;
int ct = 0;
while(ct < (pos-1))
{
ct++;
index = index->next;
}
LinkList tmp = index->next;
index->next = tmp->next;
free(tmp);
return ;
}
int GetMidElem(LinkList &L,int pos)
{
LinkList index = L;
int ct = 0;
while(ct < pos)/// 注意:定位元素时候找的是要定位的指针
{
ct++;
index = index->next;
}
return index->data;
}
void TrverseLinklist(LinkList &L)
{
LinkList index = L->next;
for (; index != NULL ; index = index->next)
{
cout<<index->data<<" ";
}
cout<<endl;
}
int main()
{
int n,m;
cin>>n>>m;
LinkList Lk = CreateLinkList(n);
int mid = (n-m + 1)/2; /// 注意:m 后来改为自减少
while (m--)
{
int pos;
cin>>pos;
DeleteByPos(Lk,pos);
}
cout<<GetMidElem(Lk,mid)<<endl;
return 0;
}
/*
10 9
10 9 8 7 6 5 4 3 2
7 4
1 2 3 4
*/