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 | void reverse(IntNodePtr head){ Stack stack(getSizelinkedList(head)); IntNodePtr temp = head; while(NULL != temp){ stack.push(temp->getData()); temp = temp->getLink(); } temp = head; while(NULL != temp){ temp->setData(Stack.pop()); temp = temp->getLink(); } } int getSizelinkedList(IntNodePtr head){ IntNodePtr temp = head; int counter = 0; while(NULL != temp){ temp = temp->getlink(); counter++; } return counter; } |