struct Lists *createLevelLinkedList(struct Tree *tree) { struct Lists *lists = (struct Lists *)malloc(sizeof(struct Lists)); if (lists == NULL) { fprintf(stderr, "createLevelLinkedList():malloc lists error.\n"); return NULL; } lists->first = NULL; lists->last = NULL; if (tree->root == NULL) { return lists; } struct List *current = createList(); addListNode(current, tree->root); while (!isEmptyList(current)) { addLists(lists, current); struct List *parent = current; current = createList(); struct ListNode *node = NULL; while ((node = getNode(parent, 1)) != NULL) { addListNode(current, node->value->left); addListNode(current, node->value->right); } } return lists; }
int main() { head1 = createList(); head2 = createList(); printf("\nFirst list is:\n"); displayList(head1); printf("\nSecond list is:\n"); displayList(head2); head = addLists(head1, head2); printf("\nThe sum results as: \n"); displayList(head); return 1; }
int main(){ Node *head1 = NULL; insert(&head1, 5); insert(&head1, 6); insert(&head1, 3); printList(head1, 1); Node *head2 = NULL; insert(&head2, 8); insert(&head2, 4); insert(&head2, 2); printList(head2, 2); Node *res = addLists(head1, head2); printList(res,3); return 0; }
int main() { int num1, num2; printf("Enter two numbers: "); scanf("%d %d", &num1, &num2); if (num1 < 0 || num2 < 0) { return 0; } struct node *h1 = makeList(num1); struct node *h2 = makeList(num2); struct node *h3 = addLists(h1, h2); // sum list printf("\nSum: "); displayNum(h3); return 0; }
struct node * addLists(struct node *num1, struct node *num2) { struct node *sum = NULL; static struct node *saveEnd2 = NULL; int carry; static int count = 0; if (num1->next != NULL) { count++; sum = addLists(num1->next,num2->next); count--; if (sum->data >=10) { sum->data = sum->data -10; carry = 1; } else { carry = 0; } num1->data = num1->data + num2->data + carry; if (count > 0) { return num1; } else { if (num1->data >=10) { num1->data = num1->data - 10; saveEnd2->data = carry; saveEnd2->next = num1; num1 = saveEnd2; return num1; } else { return num1; } } } else { num1->data = num1->data + num2->data; saveEnd2 = num2; return num1; } }
IE_Exp_OpenXML_Listener::IE_Exp_OpenXML_Listener(PD_Document* doc) : pdoc(doc), tableHelper(doc), document(NULL), section(NULL), savedSection(NULL), paragraph(NULL), savedParagraph(NULL), hyperlink(NULL), textbox(NULL), bInHyperlink(false), bInTextbox(false), idCount(10) //the first ten IDs are reserved for the XML file references { document = OXML_Document::getNewInstance(); if(!pdoc->tellListener(static_cast<PL_Listener *>(this))) document = NULL; if(setPageSize() != UT_OK) { UT_DEBUGMSG(("FRT: ERROR, Setting page size failed\n")); } if(addDocumentStyles() != UT_OK) { UT_DEBUGMSG(("FRT: ERROR, Adding Document Styles Failed\n")); document = NULL; } if(addLists() != UT_OK) { UT_DEBUGMSG(("FRT: ERROR, Adding Lists Failed\n")); document = NULL; } if(addImages() != UT_OK) { UT_DEBUGMSG(("FRT: ERROR, Adding Images Failed\n")); document = NULL; } }
int main(int argc, char *argv[]) { /* printf("Argument count: %d\n", argc); for (int i = 0; i < argc; i++) { printf("Argument vector values:%s at %p memory\n", argv[i], argv[i]); for (char *j=argv[i]; *j!='\0'; j++) { printf("Another way to print argument vector values: " "%c at %p memory\n", *j, j); } } */ //int num1[MAX_LEN] = {7,2,0,3,7}; int num1[MAX_LEN-3] = {3,7}; struct node *head1 = NULL; /* beginning */ head1 = newNode(num1[0]); //head1 = addNodetoFront(head1,num1[0]); //head1 = addNodetoFront(head1,num1[2]); //head1 = addNodetoFront(head1,num1[1]); //head1 = addNodetoFront(head1,num1[0]); printf("Num1 : %d%d%d%d%d\n",num1[0],num1[1],num1[2],num1[3],num1[4]); iterateNodes(head1); //int num2[MAX_LEN] = {2,8,9,7,1}; //int num2[MAX_LEN-1] = {8,9,7,1}; int num2[MAX_LEN-2] = {9,7,1}; struct node *head2 = NULL; /* beginning */ head2 = newNode(num2[2]); head2 = addNodetoFront(head2,num2[1]); head2 = addNodetoFront(head2,num2[0]); //head2 = addNodetoFront(head2,num2[0]); //head2 = addNodetoFront(head2,num2[0]); printf("Num1 : %d%d%d%d%d\n",num2[0],num2[1],num2[2],num2[3],num2[4]); iterateNodes(head2); int lenNum1 = 0, lenNum2 = 0; lenNum1 = findLen(head1); printf("Lenght of num1: %d\n",lenNum1); lenNum2 = findLen(head2); printf("Lenght of num2: %d\n",lenNum2); if (lenNum1 < lenNum2) { head1 = padList(head1, lenNum1, lenNum2); iterateNodes(head1); } else { head2 = padList(head2, lenNum2, lenNum1); iterateNodes(head2); } struct node *sum = NULL; /* beginning */ sum = addLists(head1,head2); printf("\nFreeing Linked List sum:\n"); struct node *temp; while (sum!=NULL) { printf("Value: %d, Address: %p, Next Address: %p\n",sum->data,sum,sum->next); temp = sum; sum=sum->next; free(temp); } printf("\nFreeing Linked List num 1:\n"); while (head1!=NULL) { printf("Value: %d, Address: %p, Next Address: %p\n",head1->data,head1,head1->next); temp = head1; head1=head1->next; free(temp); } printf("\nFreeing Linked List num 2:\n"); while (head2!=NULL) { printf("Value: %d, Address: %p, Next Address: %p\n",head2->data,head2,head2->next); temp = head2; head2=head2->next; free(temp); } //head = NULL; /* Mark list as empty*/ return 0; }