int main (void) { puts("\n 작성자 : 201121403 한대호"); ListHead *A, *B, *C; A = createLinkedList(); B = createLinkedList(); C = createLinkedList(); addLastNode(A, 4,3); addLastNode(A, 3,2); addLastNode(A, 5,1); printf("\n A(x) = "); printPoly(A); addLastNode(B, 3,4); addLastNode(B, 1,3); addLastNode(B, 2,1); addLastNode(B, 1,0); printf("\n B(x) = "); printPoly(B); addPoly(A, B, C); printf("\n C(x) = "); printPoly(C); getchar(); return 0; }
void Result(int input, int output){ sll result; sll head1 = createLinkedList(input); sll head2 = createLinkedList(output); printf("\n"); result = sortAscDesc(head1); compare(result, head2); }
/* * brief @ To get the dominatorFrontiers of a node. * Example: * * | Entry DF(A) = { A } * \/ DF(B) = { D } * [ A ]<<<< DF(C) = { D } * | | /\ DF(D) = { A } * \/ \/ /\ * [B] [C] /\ * | | /\ * \/ \/ /\ * [D] >>>>>>> * * * brief @ There is three condition to be a dominatorFrontier of the node: * 1) the node(or the children of the node) must be an immediate predeccessor of domFrontier. * 2) (if any) to get domFrontiers from grandchild(child of child), the child must be dominated by the node * 3)domFrontier is not strictly dominated by the node * * param @ Node* node - The node that is going to use this function to find the domFrontiers of it. * * retval@ LinkedList* - The list of domFrontiers of the 'Node* node' is going to return. */ LinkedList* getNodeDomFrontiers(Node* node){ LinkedList* domFrontiers = createLinkedList(); LinkedList* checklist = createLinkedList(); ListElement* tempCLElement = NULL; ListElement* tempHeadCL = NULL; Node *tempImdDom = NULL; int i = 0; if(!node->numOfChild) return domFrontiers; addListLast(checklist, node); tempHeadCL = checklist->head; while(tempHeadCL){ for( i = 0; i < ((Node*)tempHeadCL->node)->numOfChild; i++){ tempImdDom = ((Node*)tempHeadCL->node)->children[i]->imdDom; //checking the imdDom of the child isn't the parentNode; imdDom of the parentNode is NULL if(tempImdDom){ while(tempImdDom->rank > node->rank){ tempImdDom = tempImdDom->imdDom; } } //the child is not strictly dominated by the node if(tempImdDom != node || !tempImdDom){ addListLast(domFrontiers, ((Node*)tempHeadCL->node)->children[i]); continue; //any grandchild need to be dominated by node, otherwise the child of grandchild cannot be DF of node } tempCLElement = checklist->head; //checking is the children already put in the checklist while(tempCLElement){ if( ((Node*)tempHeadCL->node)->children[i] == tempCLElement->node ) break; tempCLElement = tempCLElement->next; } if(!tempCLElement) addListLast(checklist, ((Node*)tempHeadCL->node)->children[i]); } tempHeadCL = tempHeadCL->next; } return domFrontiers; }
void init(void) { mapState.border = createPanelBorder(X_BORD, Y_BORD, WIDTH_BORD); mapState.button_rect = initRect(); mapState.button_triangle = initTriangle(); mapState.button_line = initLine(); mapState.button_circle = initCircle(); mapState.points_storage = createLinkedList(); mapState.edges_storage = createLinkedList(); }
int main() { Node<int> *lists[3] = { createLinkedList({1, 2, 3, 4, 5}), createLinkedList({6, 2, 3, 4, 5}), createLinkedList({7, 8, 4, 5}) }; findInLists(lists, 3); for (auto list: lists) { freeLinkedList(list); } return 0; }
int main() { long number; number = NUMBER; long num, maxPrime; maxPrime = 0; num = 1; linkedList *primeList; primeList = createLinkedList(); enlist(primeList, 2); while (num <= number) { if (checkPrime(primeList, num) && num > maxPrime) { maxPrime = num; printf("%ld\n", maxPrime); if (number%maxPrime == 0) { number /= maxPrime; } } num += 2; } printf("The largest prime factor is: %ld\n", maxPrime); printf("destroying linked list...\n"); destroyLinkedList(primeList); return 0; }
int main(int argc, char* argv[]) { if( argc != 2 ) return 0; struct linkedList * b = createLinkedList(); /* Test Area Start printf("For starters_ front: %d, back: %d \n", frontList(b), backList(b)); printf("empty: %d \n", isEmptyList(b)); addFrontList(b,24); addFrontList(b,33); printf("front: %d, back: %d \n", frontList(b), backList(b)); addBackList(b,69); printf("front: %d, back: %d \n", frontList(b), backList(b)); removeBackList(b); printf("front: %d, back: %d \n", frontList(b), backList(b)); removeFrontList(b); printf("front: %d, back: %d \n", frontList(b), backList(b)); printf("empty: %d \n", isEmptyList(b)); removeFrontList(b); printf("front: %d, back: %d \n", frontList(b), backList(b)); printf("empty: %d \n", isEmptyList(b)); //bag interface addList(b,13); addList(b,8); printf("contains (0): %d \n", containsList(b,1)); printf("contains (1): %d \n", containsList(b,13)); printf("contains (2): %d \n", containsList(b,8)); removeList(b,13); printf("contains (0): %d \n", containsList(b,13)); addList(b,663); removeList(b,8); printf("contains (0): %d \n", containsList(b,8)); Test Area End */ int n = atoi(argv[1]);/*number of elements to add*/ int i; for( i = 0 ; i < n; i++) addList(b, (TYPE)i);/*Add elements*/ double t1 = getMilliseconds();/*Time before contains()*/ for(i=0; i<n; i++) containsList(b, i); double t2 = getMilliseconds();/*Time after contains()*/ printf("%d %g\n", n, t2-t1); return 0; }
char * intProccess(char * s) {/*{{{*/ StrInputStream ssin; // StrOutputStream ssout; LinkedList * l = createLinkedList(sizeof(int), intGreater); int x; initStrInputStream(&ssin, s); initStrOutputStream(&ssout, 250); // printf("%d\n", (ssout.length)); while (!sisEof(&ssin)) { readInt(&ssin, &x); if (listSearch(l, &x) == l->nil) { ListNode * a = l->nil->next; while (a != l->nil && *((int *)(a->key)) < x) { a = a->next; } listInsert(l, a, &x); } } listTravers(l, putInt); clrListedList(l, NULL); writeString(&ssout, "\n"); return ssout.begin; }/*}}}*/
Node* createNode(int thisRank){ Node* newNode = malloc(sizeof(Node)); newNode->rank = thisRank; newNode->visitFlag = 0; newNode->block = createLinkedList(); newNode->parent = NULL; newNode->lastBrhDom = NULL; newNode->imdDom = NULL; newNode->numOfChild = 0; newNode->children = NULL; newNode->domFrontiers = NULL; newNode->directDom = createLinkedList(); return newNode; }
void test_list_Add_should_add_first_new_element_properly(){ LinkedList *list; list = createLinkedList(); Element arrayElement[] = {{.next = NULL, .data = 1}};
int main(int argc, char* argv[]) { struct linkedList *b; int n, i; double t1, t2; for(n=1000; n < 200000; n=n*2) /* outer loop */ { b = createLinkedList(); for( i = 0 ; i < n; i++) { addList(b, (TYPE)i); /*Add elements*/ } t1 = getMilliseconds();/*Time before contains()*/ for(i=0; i<n; i++) { removeList(b, i); } t2 = getMilliseconds();/*Time after contains()*/ printf("Time for running contains() on %d elements: %g ms\n", n, t2-t1); /* delete DynArr */ deleteLinkedList(b); } return 0; }
/* Create a new Stack Input: none Output: none Return: newStack A new created stack that used to store pushed data. */ Stack *createStack() { LinkedList *list = createLinkedList(); Stack *newStack = (Stack*)list; newStack->topOfStack = list->head; return newStack; }
void test_single_linked_list() { LinkedList *list = createLinkedList(); printf("Starting size of the list: %d\n", sizeOfList(list)); insertNumber(5, list); printf("Inserting number into list, new size: %d\n", sizeOfList(list)); removeAll(list); free(list); }
static void doTest(std::vector<int> vecNums, bool bHasCircle) { std::vector<ListNode> vecNodes; ListNode *pHead = createLinkedList(&vecNodes, vecNums); Solution solution; if (solution.hasCycle(pHead) != bHasCircle) std::printf("Test failed!\n"); }
void main() { typedef struct node NODE; NODE *ll1; printf("Enter first linked list elements in sorted order only\n"); ll1 = createLinkedList(); median_LinkedList(ll1); }
void main() { //std::cout<< "hello world"; ListNode* start = createLinkedList(); ListNode* result = Solution::deleteDuplicates(start); printLinkedList(result); std::cin; }
Queue * createQueue() { Queue *queue = malloc(sizeof(Queue)); queue -> list = createLinkedList(); queue -> size = 0; return queue; }
void test_createLinkedList_should_return_initialized_LinkedList_object(){ LinkedList *list; list = createLinkedList(); TEST_ASSERT_NOT_NULL(list); TEST_ASSERT_NULL(list->head); TEST_ASSERT_NULL(list->tail); TEST_ASSERT_EQUAL(0,list->length); }
// returns the pointer to the list; NULL if list not created Priority_queue_p createPQ() { int i = 0; Priority_queue_p pq_ptr = malloc(sizeof(struct Priority_queue)); for (i = 0; i < PRIORITY_COUNT; i++) { pq_ptr->Queue_List[i] = createLinkedList(); } pq_ptr->topPriority = 16; return pq_ptr; }
void test_linked_list_return_5(void) { LinkList* NewLink = malloc(sizeof(LinkList*)); NewLink = createLinkedList(); NewLink = addList(NewLink, 5, NULL); TEST_ASSERT_EQUAL(5,NewLink->head->value); TEST_ASSERT_NULL(NewLink->head->next); printf("NewLink->head->value = %i \nNewLink->head->next = %i",NewLink->head->value, NewLink->head->next); }
int main(void) { struct Node *head = createLinkedList(); assert(head != NULL); printf("%.3lf\n", fun(head)); freeLinkedList(head); return 0; }
void test_keyFind_Function_given_Key_is_NULL_should_return_NULL() { ListElement *findEle; LinkedList *list; list=createLinkedList(); findEle=keyFind(list,NULL,strCompare); TEST_ASSERT_NULL(findEle); }
void test_keyFind_Function_given_Compare_Function_is_NULL_should_return_NULL() { ListElement *findEle; LinkedList *list; char *strTest="forTesting"; list=createLinkedList(); findEle=keyFind(list,strTest,NULL); TEST_ASSERT_NULL(findEle); }
void addPoly(ListHead * A, ListHead * B, ListHead * C) { ListNode * pA = A -> head; ListNode * pB = B -> head; ListNode * pC = C -> head; //C 선형 리스트의 노드들을 가리키기위한 포인터 변수 선언; ListHead * temp; // 임시로 입력받을 선형리스트를 만들기위한 포인터 변수 선언; ListNode * pT; //임시로 입력받을 선형리스트의 노드들의 주소값을 받기 위한 포인터 변수; float mul; //밑을 곱한값을 저장하기위한 변수 float sum; int exMul; //곱을 할경우 지수가 더해지므로 저장하기위한 변수 for( ; pB != NULL; pB = pB -> link) // 리스트 B의 노드들을 리스트 A에 하나씩 곱해주기 위한 반복문 { temp = createLinkedList(); // 리스트 temp를 생성 pT = temp -> head; //포인터 변수 pT에 리스트 temp의 헤드노드의 주소값 저장 pA = A -> head; //리스트 A의 처음노드부터 다시 계산해야 하므로 head노드의 주소값으로 다시 초기화 해준다. while(pA && pB) { mul = pA -> coef * pB -> coef; // 밑을 곱해준다 exMul = pA -> expo + pB -> expo; // 지수를 더해준다 addLastNode(temp, mul, exMul); //리스트 temp에 밑과 지수를 넣어준다 pA = pA -> link; //리스트 A 에서 다음노드로 이동 } pT = temp -> head; //리스트 temp 의 처음노드부터 다시 연산하기위해 초기화 pC = C -> head; //리스트 C의 처음노드부터 다시 연산하기위해 초기화 while(pC && pT){ if(pC -> expo == pT->expo){ //리스트 C와 리스트 temp의 지수가 같으면 리스트 C의 현재 가리키고있는 노드에 다항식의 계산을 대입 sum = pC->coef + pT->coef; pC->coef = sum; pC->expo = pC->expo; pC = pC -> link; pT = pT->link; } else if(pC -> expo > pT -> expo){ //리스트 C의 지수가 더 크면 다음 노드로 이동 pC = pC->link; } else { //리스트 temp의 지수가 더크면 리스트 C에 새로운 노드를 추가하여 다항식 추가 addLastNode(C, pT->coef, pT->expo); pT=pT->link; } } for(; pC != NULL; pC = pC->link) addLastNode(C, pC->coef, pC->expo); for(; pT != NULL; pT = pT->link) addLastNode(C, pT->coef, pT->expo); free(temp); //임시적으로 사용하는 리스트 temp를 메모리에서 해제한다. } }
int main() { int arr[] = {3, 4, 5, 6, 7}; std::vector<int> array(arr, arr+sizeof(arr)/sizeof(int)); struct node * head = new struct node; createLinkedList(array, &head); displayList(head); // reverse(&head); reverseRecursive(&head); displayList(head); return 0; }
void initTcb(){ CpuContext *cc = (CpuContext *)(((uint32_t)(&taskOneStack[1024])) - sizeof(CpuContext)); CpuContext *cc2 = (CpuContext *)(((uint32_t)(&taskOneStack[1024])) - sizeof(CpuContext)); mainTcb.name = "main thread"; mainTcb.sp = 0; taskOneTcb.name = "thread _1"; taskOneTcb.sp = (uint32_t)cc; cc->r0 = 0x00000001; cc->r1 = 0x11111111; cc->r2 = 0x22222222; cc->r3 = 0x33333333; cc->r4 = 0x44444444; cc->r5 = 0x55555555; cc->r6 = 0x66666666; cc->r7 = 0x77777777; cc->r8 = 0x88888888; cc->r9 = 0x99999999; cc->r10 = 0xaaaaaaaa; cc->r11 = 0xbbbbbbbb; cc->r12 = 0xcccccccc; cc->lr = 0xFFFFFFF9; cc->pc = (uint32_t*)taskOne; cc->xpsr = 0x01000000; taskTwoTcb.name = "thread _2"; taskTwoTcb.sp = (uint32_t)cc2; cc2->r0 = 0xFFFFFFF9; cc2->r1 = 0xcccccccc; cc2->r2 = 0xbbbbbbbb; cc2->r3 = 0xaaaaaaaa; cc2->r4 = 0x99999999; cc2->r5 = 0x88888888; cc2->r6 = 0x77777777; cc2->r7 = 0x66666666; cc2->r8 = 0x55555555; cc2->r9 = 0x44444444; cc2->r10 = 0x33333333; cc2->r11 = 0x22222222; cc2->r12 = 0x11111111; cc2->lr = 0x00000001; cc2->pc = (uint32_t*)taskTwo; cc2->xpsr = 0x01000000; runningQueue = &mainTcb; readyQueue = &taskOneTcb; createLinkedList(&taskOneTcb); }
int main() { int arr[] = {3, 4, 5, 6, 7}; std::vector<int> array(arr, arr+sizeof(arr)/sizeof(int)); struct node * head = new struct node; createLinkedList(array, *head); displayList(head); reverse(head); std::cout<<"here"<<std::endl; displayList(head); return 0; }
int main() { int a[] = {1,2,3,4,2,4,7,8}; int i; for (i=0; i<sizeof(a)/sizeof(a[0]); i++) { printf("%d ", a[i]); } printf("\n"); node *head = createLinkedList(a, sizeof(a)/sizeof(a[0])); printList(head); removeDup(head); printList(head); }
int main() { int a[] = {1,2,3,4,5,6,7,8,9,10}; int size = sizeof(a)/sizeof(a[0]); int i; for (i=0; i<size; i++) { printf("%d ", a[i]); } printf("\n"); node *head = createLinkedList(a, size); printLinkedList(head); node *kth = returnKthkey(head, size, 4); printf("%d\n", kth->key); }
int main(int argc, char* argv[]) { int returned = -1; struct linkedList* q = createLinkedList(3); printf("Checking if the list is empty: %d\n", isEmptyList(q)); printf("Attempting to add to front \n"); addFrontList(q, 1); removeList(q, 1); printf("Checking if the list is empty: %d\n", isEmptyList(q)); addFrontList(q, 2); addFrontList(q, 3); _printList(q); printf("Attempting to add to back \n"); addBackList(q, 4); addBackList(q, 5); addBackList(q, 6); _printList(q); printf("Attempting to print front \n"); printf("%d\n", frontList(q)); printf("Attempting to print back \n"); printf("%d\n", backList(q)); printf("Attempting to remove front \n"); removeFrontList(q); _printList(q); printf("Attempting to remove back \n"); removeBackList(q); _printList(q); printf("Attempting to delete 4 \n"); removeList(q, 4); _printList(q); printf("Attempting to print list \n"); _printList(q); printf("Attempting to confirm contains 5 \n"); returned = containsList(q, 5); if (returned == 1) printf("true \n"); else printf("false \n"); return 0; }