int main() { printf("at beginning of main\n"); FILE *fpIn; int MAX_SIZE = 100; int count = 0; int i; int tempArray[MAX_SIZE]; int line[MAX_SIZE]; // fpIn = fopen(*argv, "r" ); fpIn = fopen("input1.txt", "r" ); if( !fpIn ) { printf("Unable to open: input1.txt\n" ); exit(-1); } printf("before read in of file\n"); while (!feof(fpIn)) // while (fpIn != NULL) { fscanf(fpIn, "%d", line); //fgets(line, MAX_SIZE, fpIn); tempArray[count] = line; count++; } printf("before print out of array for testing. Count: %d. \n", count); // Print out temp array for testing int j; for( j = 0; j < count; j++) { printf("%d", tempArray[j]); } printf("before putting infor into queue"); // Put data into Queue for(i = 0; i < count ; i++) { put(tempArray[i]); } // Print out list printf("before printing list"); PrintList(); printf("after printing list"); fclose(fpIn); return 0; }
int main(void) { Menu menu; List list; InitList(&list); do { Data x; switch (menu = SelectMenu()) { case InsFront: x = Read("先頭に挿入", NO | NAME); InsertFront(&list, x); break; case InsRear: x = Read("末尾に挿入", NO | NAME); InsertRear(&list, x); break; case RmvFront: RemoveFront(&list); break; case RmvRear: RemoveRear(&list); break; case PrintCrnt: PrintCrntNode(&list); break; case RmvCrnt: RemoveCrnt(&list); break; case SrchNo: x = Read("探索", NO); if (SearchNode(&list, x, NoEqual) != NULL){ PrintCrntNode(&list); } break; case SrchName: x = Read("探索", NAME); if(SearchNode(&list, x, NameEqual) != NULL){ PrintCrntNode(&list); } break; case PrintAll: PrintList(&list); break; case Clear: ClearList(&list); break; } } while (menu != Term); TermList(&list); return (0); }
int main(){ List L; CreateList(L); InsertElem(L, 1, 100); InsertElem(L, 2, 200); InsertElem(L, 3, 300); InsertElem(L, 6, 500); PrintList(L); backPrintList(L); }
PRIVATE inline void PrintCall(GBUF *out, UNUSED(Node *node), callNode *u, int offset, UNUSED(Bool norecurse)) { gbputs("Call: ", out); PrintCRSpaces(out, offset + 2); PrintNode(out, u->name, offset + 2); PrintCRSpaces(out, offset + 2); gbputs("List: args", out); PrintCRSpaces(out, offset + 4); PrintList(out, u->args, offset + 4); }
int main(void) { FILE *fp = OpenFile(FILENAME); List *head = CreateList(fp); fclose(fp); FreeList(PrintList(head)); return EXIT_SUCCESS; }
int main (int argc, char* argv[]) { int dataInt[] = {1, 2, 3, 4, 5}; CSinglyListNode* head = CreateTestList(dataInt, 5); PrintList(head); CSinglyListNode* deleteMe = NULL; // Test 1 deleteMe = Find(head, 2); if (deleteMe) { if (!DeleteElement(&head, deleteMe)) std::cout << "Can't delete : " << deleteMe->iData << std::endl; } PrintList(head); // Test 2 deleteMe = Find(head, 7); if (!deleteMe) { std::cout << "This element 7 doesn't exist" << std::endl; } // Test 3 deleteMe = Find(head, 5); if (deleteMe) { if (!DeleteElement(&head, deleteMe)) std::cout << "Can't delete : " << deleteMe->iData << std::endl; } PrintList(head); // Test 3 std::cout << "DeleteList..." << std::endl; DeleteList(&head); std::cout << "head now : " << head << std::endl; PrintList(head); std::cout << "bye" << std::endl; return 0; }
// ====================测试代码==================== ListNode* Test(char* testName, ListNode* pHead1, ListNode* pHead2) { if(testName != NULL) printf("%s begins:\n", testName); printf("The first list is:\n"); PrintList(pHead1); printf("The second list is:\n"); PrintList(pHead2); printf("The merged list is:\n"); ListNode* pMergedHead = Merge(pHead1, pHead2); PrintList(pMergedHead); printf("\n\n"); return pMergedHead; }
// DataSetList::List() void DataSetList::List() const { if (!hasCopies_) { // No copies; this is a Master DSL. if (DataList_.empty()) return; mprintf("\nDATASETS (%zu total):\n", DataList_.size()); } else if (DataList_.empty()) { mprintf(" No data sets."); return; } PrintList( DataList_ ); }
int main() { struct node *a = NULL; SortedInsert2(&a, MakeNode(1)); SortedInsert2(&a, MakeNode(4)); SortedInsert2(&a, MakeNode(10)); struct node *b = NULL; SortedInsert2(&b, MakeNode(3)); SortedInsert2(&b, MakeNode(9)); SortedInsert2(&b, MakeNode(21)); printf("a: "); PrintList(a); printf("b: "); PrintList(b); struct node *merged_and_sorted = SortedMerge(a, b); printf("merged_and_sorted: "); PrintList(merged_and_sorted); printf("a: "); PrintList(a); printf("b: "); PrintList(b); return 0; }
void test6() { LinkList list; LinkNode *ret = NULL; InitLinkList(&list); PushBack(&list, 3); PushBack(&list, 5); PushBack(&list, 4); PushBack(&list, 2); PushBack(&list, 1); PrintList(&list); //ret = FindNode(&list, 2); //InsertFrontNode(ret, 0); //3 5 4 0 2 1 //PrintList(&list); //ret=FindMidNode(&list); DelKNode(&list, 5); PrintList(&list); DestoryLinkList(&list); }
int main() { ListNode* pListHead = CreateList(0); for (int i = 1; i < 10; i++) InsertNode(&pListHead,i); PrintList(pListHead); return 0; }
void TestPrintLots() { List l = NULL; l = MakeArrayStackEmpty(l); int i=0; for (i = 0; i < 10; ++i) { Insert(i * i, l, l); } PrintList(l); List p = NULL; p = MakeArrayStackEmpty(p); Insert(7, p, p); Insert(5, p, p); Insert(3, p, p); Insert(1, p, p); PrintList(l); PrintLots(l, p); }
int main() { struct node *only_one = MakeNode(1); MergeSort(&only_one); struct node *two = MakeNode(2); two->next = MakeNode(1); printf("two: "); PrintList(two); MergeSort(&two); printf("two: "); PrintList(two); int spec[8] = {19, 3, 99, 1, 22, 44, 12, 2}; struct node *head = ListFromArray(spec, 8); printf("head: "); PrintList(head); MergeSort(&head); printf("head: "); PrintList(head); return 0; }
main() { struct node * HEADL1 = NULL; struct node * HEADL2 = NULL; PushNode(&HEADL1,9); PushNode(&HEADL1,7); PushNode(&HEADL1,5); PushNode(&HEADL1,2); PushNode(&HEADL1,1); PrintList(HEADL1); PushNode(&HEADL2,8); PushNode(&HEADL2,4); PushNode(&HEADL2,3); PrintList(HEADL2); struct node* dummyHEAD = NULL; dummyHEAD = MergeTwoSortedList(HEADL1, HEADL2); PrintList(dummyHEAD); }
int main(int argc, char const *argv[]) { List L; Position P; int i; L = CreateList(15); PrintList(L); for (i = 5; i < 12; ++i) { P = Find(L, i); deleteNode(P); PrintList(L); } DestroyList(L); return 0; }
int main() { List L1, L2, L3; int flag1 = 0, flag2 = 0; Position P1; Position P2; int tmp1, tmp2; L1 = Initialize(); L2 = Initialize(); L3 = Initialize(); P1 = L1; P2 = L2; //Insert(L1, 2); //空插 //Insert(L1, 5); //尾部插入 //Insert(L1, 7); //尾部插入 //Insert(L1, 3); //普通插入 //Insert(L1, 1); //首部插入 scanf("%d", &tmp1); if(tmp1 != -1){ Insert(L1, tmp1, P1); P1 = P1->next; while(scanf("%d", &tmp1)){ if(tmp1 != -1){ Insert(L1, tmp1, P1); P1 = P1->next; }else{ break; } } } scanf("%d", &tmp2); if(tmp2 != -1){ Insert(L2, tmp2, P2); P2 = P2->next; while(scanf("%d", &tmp2)){ if(tmp2 != -1){ Insert(L2, tmp2, P2); P2 = P2->next; }else{ break; } } } //L3 = Merge(L1, L2); L3 = Mix(L1, L2); PrintList(L3); return 0; }
int main(void) { //자료구조를 지역변수로 선언했기 때문에 //다른 함수에서는 직접 접근할 수 없다. int aList[5] = { 0 }; InitList(aList, 5); SortList(aList, 5); PrintList(aList, 5); return 0; }
static void LispPrintStack(struct LispStack *s, char *name) { int i; struct StackFrame *stack = s->stack; Lisp_printf("%s: stack pointer %d\n", name, s->stackPointer); for (i = 0; i < s->stackPointer; i++) { Lisp_printf("stack[%d] [%s] ", i, stack[i].name); PrintList(stack[i].value); } }
int main() { ListNode* head = NULL; PushElement( &head, 3); ListNode *temp = head; int i = 0; for( i = 0; i < 500; i++ ) { PushElement( &head->next, i % 20 ); head = head->next; } head = temp; #if 0 PushElement( &head, 3); PushElement( &(head->next), 2 ); PushElement( &(head->next->next), 2 ); PushElement( &(head->next->next->next), 1 ); PushElement( &(head->next->next->next->next, 3); PushElement( &(head->next->next->next->next->next), 2 ); PushElement( &(head->next->next->next->next->next->next), 2 ); PushElement( &(head->next->next->next->next->next->next), 1 ); PushElement( &head, 3); PushElement( &(head->next), 2 ); PushElement( &(head->next->next), 2 ); PushElement( &(head->next->next->next), 1 ); // PushElement( &(head->next->next->next->next), 1 ); #endif // Sort the linked list. MergeSortOnLL( &head ); PrintList( head ); RemoveDuplicatesFromList( head ); PrintList( head ); }
int main() { struct edges *Node=NULL; char ch; int i,j,weight; scanf("%d %d",&n,&m); if(n<=0||n>=200000) exit(EXIT_FAILURE); if(m<=0||m>=200000) exit(EXIT_FAILURE); struct node *start[n]; struct edges *ptr[n]; for(i=0;i<n;i++) { start[i]=NULL; ptr[i]=NULL; } int k; for(k=0;k<m;k++) { scanf("%d %d %d",&i,&j,&weight); if(i<=0||i>=200000) exit(EXIT_FAILURE); if(j<=0||j>=200000) exit(EXIT_FAILURE); Node=NewNode(); if(start[i]==NULL) start[i]=(struct node*)Node; else ptr[i]->next=Node; Node->vertex=j; Node->weight=weight; ptr[i]=Node; Node=NewNode(); if(start[j]==NULL) start[j]=(struct node*)Node; else ptr[j]->next=Node; Node->vertex=i; Node->weight=weight; ptr[j]=Node; } for(i=0;i<n;i++) { printf("%d ->",i); PrintList((struct edges*)start[i]); } return 0; }
/* EXPORT->PrintTranscription: for diagnostics */ void PrintTranscription(Transcription *t, char *title) { int i; LabList *ll; printf("Transcription: %s [%d lists]\n",title,t->numLists); ll = t->head; for (i=1; i<=t->numLists; i++) { printf(" List %d\n",i); PrintList(ll); ll = ll->next; } }
// insert node ahead of FreeMemHead static void InsertNodeToFreeList(FREE_MEM_T *node, UINT8 inst_no) { printD("[%d]InsertNodeToFreeList(startAddr : 0x%08x size:%ld)\n", inst_no, node->startAddr, node->size); node->next = FreeMemHead; node->prev = FreeMemHead->prev; FreeMemHead->prev->next = node; FreeMemHead->prev = node; FreeMemHead = node; #if DEBUG PrintList(); #endif }
// insert node ahead of FreeMemHead static void InsertNodeToFreeList(FREE_MEM_T *node, int inst_no) { LOG_MSG(LOG_TRACE, "InsertNodeToFreeList", "[%d]instance(startAddr : 0x%08x size:%ld cached flag : %d)\n", \ inst_no, node->startAddr, node->size, node->cacheFlag); node->next = FreeMemHead; node->prev = FreeMemHead->prev; FreeMemHead->prev->next = node; FreeMemHead->prev = node; FreeMemHead = node; PrintList(); }
int main (void) { int choice,n; LIST MyList= {NULL}; LIST *lp=&MyList; while (1) { printf ("\n--------------------------------------\n"); printf ("Choose a function for the linked list.\n\n"); printf ("1. Insert a new node.\n"); printf ("2. Print list.\n"); printf ("3. Search for a specific node.\n"); printf ("4. Delete the first node.\n"); printf ("5. Delete the last node.\n"); printf ("6. Delete a given node.\n"); printf ("7. Exit the program.\n"); printf ("--------------------------------------\n\n"); scanf ("%d",&choice); switch (choice) { case 1: printf ("Please give an integer to insert in the list.\n"); scanf ("%d",&n); InsertToFront (lp,n); break; case 2: PrintList (MyList); break; case 3: printf ("Please give an integer to look up in the list.\n"); scanf ("%d",&n); Lookup (MyList,n); break; case 4: DeleteFromFront (lp); break; case 5: DeleteFromEnd (lp); break; case 6: printf ("Please give an integer to delete from the list.\n"); scanf ("%d",&n); Delete (lp,n); break; case 7: return 0; default: printf ("Error!\n"); break; } } return 0; }
int main() { Node *Head; while(gets(buf)) { Head=NULL; rec(&Head); PrintList(Head); memset(buf,0,sizeof(buf)); } return 0; }
int main (int argc, char* argv[]) { int dataInt[] = {1, 2, 3, 4, 5}; CSinglyListNode* head = CreateTestList(dataInt, 5); PrintList(head); std::cout << "--------------AppendNode-------------" << std::endl; int data; data = 6; if (!AppendNode(&head, data)) std::cout << "failed to AppendNode: " << data << std::endl; data = 7; if (!AppendNode(&head, data)) std::cout << "failed to AppendNode: " << data << std::endl; PrintList(head); std::cout << "----------------------------------------" << std::endl; std::cout << "--------------CopyList-------------" << std::endl; CSinglyListNode* newList = NULL; if (!CopyList(NULL, &newList)) std::cout << "failed to CopyList" << std::endl; PrintList(head); PrintList(newList); if (!CopyList(head, &newList)) std::cout << "failed to CopyList" << std::endl; PrintList(head); PrintList(newList); std::cout << "----------------------------------------" << std::endl; std::cout << "bye" << std::endl; return 0; }
int main(int argc, char *arg[]) { struct node* listA = NULL; Push(&listA, 3); Push(&listA, 2); Push(&listA, 1); struct node* listB = NULL; Push(&listB, 6); Push(&listB, 5); Push(&listB, 4); printf("List A\n"); PrintList(listA); printf("List B\n"); PrintList(listB); MoveNode(&listA, &listB); printf("List A\n"); PrintList(listA); printf("List B\n"); PrintList(listB); MoveNode(&listA, &listB); printf("List A\n"); PrintList(listA); printf("List B\n"); PrintList(listB); }
int main(void) { FILE *pf; char name[20]; int TIME[15]; int time, money; int sum_time, sum_money; int t; // number of elements of array TIME int i,readt; pf = fopen("store.txt", "r"); if (pf == NULL) { perror("Cannot open file"); return (-1); } sum_time = 0; sum_money = 0; t = 0; while (fscanf(pf, "%d", &readt) > 0) { TIME[t] = readt; t++; } while (fscanf(pf, "%s %d %d", name, &money, &time) > 0) { Enque(money, time, name); } i=0; while (i < t) { NodeT *elem; elem = head; sum_time = 0; sum_money = 0; while (elem != NULL) { if ((sum_time + elem->time) <= TIME[i]) { sum_time = sum_time + elem->time; sum_money = sum_money + elem->money; } elem=elem->next; } printf("After %d seconds: %d and total amount of time %d\n", TIME[i], sum_money, sum_time); i++; } PrintList(); fclose(pf); return(0); }
int main(int argc, const char * argv[]) { Node *pList; InitialList(&pList); CreateListTailInsert(pList); PrintList(pList); BubbleSort(pList); return 0; }
void test1() { LinkList list; InitLinkList(&list); PushBack(&list, 1); PushBack(&list, 2); PushBack(&list, 3); PushBack(&list, 4); PushBack(&list, 5); PopBack(&list); PopBack(&list); PopBack(&list); PrintList(&list); PushFront(&list, 6); PushFront(&list, 7); PushFront(&list, 8); PrintList(&list); PopFront(&list); PrintList(&list); DestoryLinkList(&list); PrintList(&list); }