ikseek

Untitled

Jul 23rd, 2013
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.60 KB | None | 0 0
  1. // Убрать из списка первый элемент и вернуть его
  2. ListItem* RemoveHead(ListItem*& list) {
  3.     ListItem* old_head = list;
  4.     list = list->next;
  5.     return old_head;
  6. }
  7.  
  8. // Добавить элемент в голову списка
  9. void AddToHead(ListItem*& list, ListItem* item) {
  10.     item->next = list;
  11.     list = item;
  12. }
  13.  
  14. // Перевернуть список
  15. void ReverseList(ListItem*& list) {
  16.     ListItem* reversed_list = 0;
  17.     while (list != 0) {
  18.       ListItem* current_item = RemoveHead(list);
  19.       AddToHead(reversed_list, current_item);
  20.     }
  21.     list = reversed_list;
  22. }
Advertisement
Add Comment
Please, Sign In to add comment