-
Notifications
You must be signed in to change notification settings - Fork 49
/
Copy path2-3.cpp
53 lines (37 loc) · 814 Bytes
/
2-3.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#include <iostream>
using namespace std;
class ListNode{
public:
int val;
ListNode* next;
ListNode(int i): val(i),next(NULL){}
};
void delmid(ListNode* head){
ListNode* p = new ListNode(0);
p->next = head;
ListNode* q = head;
if (!q->next){head=NULL; return;}
while (q->next && q->next->next){
q = q->next->next;
p = p->next;
}
p->next = p->next->next;
}
int main(){
ListNode* head = new ListNode(0);
ListNode* q=head;
int a[16] = {1,2,3,4,5,6,7,8,7,6,5,4,3,2,1,0};
for (int i=0;i<16;i++){
ListNode* p=new ListNode(a[i]);
q->next = p;
q=p;
}
delmid(head);
if (head==NULL){cout << "Empty List" << endl; return 0;}
while (head!=NULL){
cout << head->val << " ";
head = head->next;
}
cout << endl;
return 0;
}