-
Notifications
You must be signed in to change notification settings - Fork 0
/
3.cpp
42 lines (37 loc) · 916 Bytes
/
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
/*************************************************************************
> File Name: 3.cpp
> Author: Louis1992
> Mail: [email protected]
> Blog: http://gzc.github.io
> Created Time: Mon Nov 9 08:35:30 2015
************************************************************************/
#include<iostream>
using namespace std;
struct ListNode {
int val;
ListNode *next;
ListNode(int _v):val(_v){}
};
void deleteNode(ListNode* node) {
ListNode* next = node->next;
node->val = next->val;
node->next = next->next;
delete next;
}
void format(ListNode *head) {
while(head) {
cout << head-> val << " ";
head = head->next;
}
cout << endl;
}
int main() {
ListNode *l1 = new ListNode(1);
ListNode *l2 = new ListNode(2);
ListNode *l3 = new ListNode(3);
l1->next = l2;
l2->next = l3;
deleteNode(l1);
format(l1);
return 0;
}