#include <stdio.h>
#include <stdlib.h>

struct Node{
int data;
Node *link;

typedef Node* NodePtr;

void addToEnd(NodePtr* head, int val);
void printList(NodePtr head);

NodePtr mergeLists(NodePtr* list1, NodePtr* list2);

int main()
int nextInt;

NodePtr list1 = NULL;
NodePtr list2 = NULL;

printf( "Enter integers in sorted order for first list, -1 to end\n");
scanf("%d, &nextInt");
while (nextInt != -1)
addToEnd(list1, nextInt);
scanf("%d, &nextInt");

printf("Enter integers in sorted order for second list, -1 to end\n");
scanf("%d, &nextInt");
while (nextInt != -1)
addToEnd(list2, nextInt);
scanf("%d, &nextInt");

NodePtr mergedList = mergeLists(list1, list2);

printf("Merged list\n");
printf("\nOriginal lists");
printf("\nlist1: ");
printf("\nlist2: ");

void addToEnd(NodePtr* head, int val)
NodePtr newNode = new Node;
newNode->data = val;
newNode->link = NULL;

if (head == NULL)
head = newNode;
NodePtr temp = head;
while (temp->link != NULL)
temp = temp->link;
temp->link = newNode;

void printList(NodePtr head)
if (head != NULL)
printf( " ",head->data);
return 0;
ROMANES EUNT DOMUS - That's an order!

what are the mistakes? what are the error messages ? what operating system? what compiler ? In otherwords, don't just toss some code out there and expect everyone to correct it. You need to explain what you want or what the problems are.

This article has been dead for over six months. Start a new discussion instead.