Advertisement
Guest User

Untitled

a guest
Jan 27th, 2013
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.51 KB | None | 0 0
  1. struct ListNode{
  2.     int value;
  3.     struct ListNode* next;
  4. };
  5.  
  6. void appendNode(struct ListNode* head, int num){
  7.     struct ListNode* nodePtr;
  8.     struct ListNode* newNode;
  9.         newNode = malloc(sizeof(struct ListNode));
  10.     newNode->value = num;
  11.     newNode->next = NULL;
  12.  
  13.     if(!head)
  14.     head = newNode;
  15.     else{
  16.         nodePtr = head;
  17.         while(nodePtr->next)
  18.             nodePtr = nodePtr->next;
  19.         nodePtr->next = newNode;
  20.     }
  21. }
  22.  
  23. int main(){
  24.     struct ListNode* head;
  25.     head = NULL;
  26.     appendNode(head, 5);
  27.     printf("%p", head);
  28.  
  29. return 0;
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement