Ejemplo n.º 1
0
/* Driver program to test above function */
int main(void)
{
  struct Node* result = NULL;
  struct Node* first = NULL;
  struct Node* second = NULL;

  // create first list 7->5->9->4->6
  push(&first, 6);
  push(&first, 4);
  push(&first, 9);
  push(&first, 5);
  push(&first, 7);
  printf("First List is ");
  printList(first);

  // create second list 8->4
  push(&second, 4);
  push(&second, 8);
  printf("Second List is ");
  printList(second);

  // Add the two lists and see result
  result = addTwoLists(first, second);
  printf("Resultant list is ");
  printList(result);

 return 0;
}
Ejemplo n.º 2
0
int main(void)
{
    struct node* res = NULL;
    struct node* first = NULL;
    struct node* second = NULL;
 
    push(&first, 6);
    push(&first, 4);
    push(&first, 9);
    push(&first, 5);
    push(&first, 7);
    printf("First List is ");
    printList(first);
 
    push(&second, 4);
    push(&second, 8);
    printf("Second List is ");
    printList(second);
 
    res = addTwoLists(first, second);
    printf("Resultant list is ");
    printList(res);
 
   return 0;
}
Ejemplo n.º 3
0
int main() {
	Node head1 = nodeCreate(3);
	Node head2 = nodeCreate(3);

	int array1[] = {8,7,8,9,2};
	for(int i = 0; i < 2; i++) {
		head1 = listAppend(head1, array1[i]);
	}
	int array2[] = {4,5,3};
	for(int i = 0; i < 2; i++) {
		head2 = listAppend(head2, array2[i]);
	}

	printf("1.1 list 1 and the linked list is now:\n");

	Node item = head1;
	while(item->next != NULL) {
		printf("%d ", item->num);
		item = item->next;
	}
	printf("%d\n\n\n\n", item->num);

	printf("1.2 list 2 and the linked list is now:\n");

	item = head2;
	while(item->next != NULL) {
		printf("%d ", item->num);
		item = item->next;
	}
	printf("%d\n\n\n\n", item->num);

	Node head = addTwoLists(head1, head2);

	item = head;
	while(item->next != NULL) {
		printf("%d ", item->num);
		item = item->next;
	}
	printf("%d\n\n\n\n", item->num);

	return 0;
}