Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
Tags
- Book review
- Software Engineering
- MySQL
- RFID
- program
- leadership
- agile
- Spain
- Malaysia
- Book
- essay
- Python
- comic agile
- Programming
- Kuala Lumpur
- Italy
- web
- psychology
- hbase
- Linux
- ubuntu
- history
- management
- QT
- programming_book
- France
- erlang
- django
- Java
- hadoop
Archives
- Today
- Total
linked list를 node 두 개씩 거꾸로 바꾸기 본문
http://www.careercup.com/question?id=58132
1. Implement memcopy considering the overlap
2. Given a linked list:
a->b->c->d....
Write a function to swap the each node pair , such that output will be as follows:
b->a->d->c->...
void reversePair(Node** p_ppstrHead)
{
Node* z_pstr1st = *p_ppstrHead;
Node* z_pstr2nd = (*p_ppstrHead)->next;
Node* z_pstr3rd = z_pstr1st;
*p_ppstrHead = z_pstr2nd;
while ( z_pstr1st != NULL && z_pstr2nd != NULL )
{
z_pstr1st->next = z_pstr2nd->next;
z_pstr2nd->next = z_pstr1st;
if ( z_pstr1st->next != NULL )
{
z_pstr1st = z_pstr1st->next;
}
if ( z_pstr1st != NULL )
{
z_pstr2nd = z_pstr1st->next;
if ( z_pstr2nd )
{
z_pstr3rd->next = z_pstr2nd;
z_pstr3rd = z_pstr1st;
}
}
}
}
Comments