int main() { plink ex1Head; plink oplink,tmplink; int i; ex1Head = createLinkHead(); if(ex1Head == NULL){ printf("ex1 error!\n"); return -1; } /*产生一个测试链表数据*/ oplink = ex1Head; for(i = 0; i < 5; i++){ oplink = insert_node(oplink,i+2); } printf("raw data is :\n"); show_link(ex1Head); /*倒置链表数据*/ oplink = ex1Head->next; ex1Head->next = NULL; while(oplink){ tmplink = oplink; oplink = oplink->next; tmplink->next = ex1Head->next; ex1Head->next = tmplink; } printf("resver data is :\n"); show_link(ex1Head); return 0; }
int main(int argc, const char *argv[])//主函数 代码如下 { STU *head = NULL; int flag = 1; char choice=0; head = read_data(); while(flag>0) { menu(); choice = getchar(); getchar(); switch(choice) { case '1' :head=add_node(head);break; case '2' :head=delete_node(head);break; case '3' :show_link(head);break; case '4' :save_link(head);break; case '5' :flag = 0;break; default:printf("error\n"); } } return 0; }
int main(void) { //printf("sucess 1 !\n"); int i = 0; head = (struct mylink*)malloc(sizeof(struct mylink)); //合并用的链表 headA = (struct mylink*)malloc(sizeof(struct mylink)); headB = (struct mylink*)malloc(sizeof(struct mylink)); if (head == NULL || headA==NULL || headB == NULL){ printf("malloc error!\n"); return -1; } //printf("sucess 2 !\n"); head->value = 0; head->next =NULL; headA->value = 0; headA->next =NULL; headB->value = 0; headB->next =NULL; for (i = 0; i < 10;i++){ insert_value(head,i+2); } for (i = 1;i < 10;i++){ insert_value(headA,i*2-1); insert_value(headB,i*2); } printf("=================Test 1&2 ======!\n"); #if 1 //------------------测试1&2 printf("------------creat show--------\n"); show_link(head); //打印创建好的链表 printf("----------reverst show----------\n"); reverse_link(head); //翻转链表 show_link(head); //打印翻转后的链表 printf("-------------- kill 4 show------\n"); delete_link(head,4); //删除链表中的某块数据 show_link(head); //打印删除后的链表 #endif //-------------测试 3 printf("=================Test 3 ======!\n"); printf("-------------- headA befor show------\n"); reverse_link(headA);show_link(headA); //打印A 链表 printf("-------------- headB befor show------\n"); reverse_link(headB);show_link(headB); //打印B 链表 headA = mergelink(headB,headA); //合并 A B 链表 printf("-------------- headAB befor show------\n"); show_link(headA);//打印合并后的链表 printf("=================Test 4 ======!\n"); josephus(8,4,3);//问题4 printf("sucess !\n"); return 0; }
void show_text(TextNode *node, int Ender) { /*int twidth, len;*/ /*int otext_x, otext_y, t;*/ /*XFontStruct *old_font;*/ /*int old_color;*/ for (; node != NULL; node = node->next) { switch (node->type) { case 0: case Beginitems: case Begintitems: case Bound: case Center: case Free: case HSpace: case Indent: case Indentrel: case Item: case Macro: case Mbox: case Newline: case Noop: case Par: case Pound: case Rbrace: case Space: case Tab: case Table: case Titem: case VSpace: break; case Dash: case Fi: case Ifcond: if (visible(node->y, node->height)) { if (strlen(node->data.text) > 1) { XDrawLine(gXDisplay, gWindow->fDisplayedWindow, gWindow->fStandardGC, node->x, node->y + gRegionOffset + y_off - gTopOfGroupStack->cur_font->descent - word_off_height, node->x + node->width, node->y + gRegionOffset + y_off - word_off_height - gTopOfGroupStack->cur_font->descent); } else { XDrawString(gXDisplay, gWindow->fDisplayedWindow, gWindow->fStandardGC, node->x, node->y + gRegionOffset - gTopOfGroupStack->cur_font->descent + y_off, node->data.text, 1); } } else { if (above(node->y)) need_scroll_up_button = 1; else if (below(node->y)) need_scroll_down_button = 1; } break; case Lsquarebrace: case Math: case Punctuation: case Rsquarebrace: case Spadsrctxt: case WindowId: case Word: if (visible(node->y, node->height)) XDrawString(gXDisplay, gWindow->fDisplayedWindow, gWindow->fStandardGC, node->x, node->y + gRegionOffset - gTopOfGroupStack->cur_font->descent + y_off, node->data.text, node->width); else { if (above(node->y)) need_scroll_up_button = 1; else if (below(node->y)) need_scroll_down_button = 1; } break; case Verbatim: push_group_stack(); tt_top_group(); if (visible(node->y, node->height)) XDrawString(gXDisplay, gWindow->fDisplayedWindow, gWindow->fStandardGC, node->x, node->y + gRegionOffset - gTopOfGroupStack->cur_font->descent + y_off, node->data.text, node->width); else { if (above(node->y)) need_scroll_up_button = 1; else if (below(node->y)) need_scroll_down_button = 1; } pop_group_stack(); break; case Horizontalline: if (visible(node->y, node->height)) { line_top_group(); XDrawLine(gXDisplay, gWindow->fDisplayedWindow, gWindow->fStandardGC, 0, node->y + gRegionOffset + y_off, gWindow->width, node->y + gRegionOffset + y_off); pop_group_stack(); } else { if (above(node->y)) need_scroll_up_button = 1; else if (below(node->y)) need_scroll_down_button = 1; } break; case Box: if (visible(node->y, node->height)) XDrawRectangle(gXDisplay, gWindow->fDisplayedWindow, gWindow->fStandardGC, node->x, node->y + gRegionOffset + y_off - node->height, node->width, node->height); else { if (above(node->y)) need_scroll_up_button = 1; else if (below(node->y)) need_scroll_down_button = 1; } break; case Downlink: case Link: case LispDownLink: case LispMemoLink: case Lispcommand: case Lispcommandquit: case Lisplink: case Lispwindowlink: case Memolink: case Qspadcall: case Qspadcallquit: case Returnbutton: case Spadcall: case Spadcallquit: case Spaddownlink: case Spadlink: case Spadmemolink: case Unixcommand: case Unixlink: case Upbutton: case Windowlink: if (pix_visible(node->y, node->height)) show_link(node); break; case Spadcommand: case Spadgraph: case Spadsrc: show_spadcommand(node); break; case Pastebutton: if (visible(node->y, node->height)) show_pastebutton(node); break; case Paste: show_paste(node); break; case Group: case Tableitem: push_group_stack(); break; case Controlbitmap: show_image(node, gWindow->fControlGC); break; case Inputbitmap: show_image(node, gWindow->fStandardGC); break; case Inputpixmap: show_image(node, gWindow->fStandardGC); break; case BoldFace: bf_top_group(); break; case Emphasize: if (gTopOfGroupStack->cur_font == gRmFont) em_top_group(); else rm_top_group(); break; case It: em_top_group(); break; case Sl: case Rm: rm_top_group(); break; case Tt: tt_top_group(); break; case Inputstring: show_input(node); break; case Radiobox: case SimpleBox: show_simple_box(node); break; case Beep: LoudBeepAtTheUser(); break; case Description: bf_top_group(); break; case Endspadsrc: case Endspadcommand: gInAxiomCommand = 1; case Endtableitem: case Enddescription: case Endpastebutton: case Endlink: case Endbutton: case Endgroup: pop_group_stack(); case Endverbatim: case Endmath: case Endbox: case Endtable: case Endmbox: case Endparameter: case Endpaste: case Endinputbox: case Endcenter: case Endmacro: case Endif: case Endtitems: case Enditems: /* * Now since I can show specific regions of the text, then at * this point I should check to see if I am the end */ if (node->type == Ender) return; break; case Endfooter: case Endscrolling: case Endheader: case Endtitle: /* * regardless of what ender I have, I always terminate showing * with one of these */ return; default: fprintf(stderr, "Show_text: Unknown Node Type %d\n", node->type); break; } } }
static void do_show_link(int argc, char *argv[]) { char *name = NULL; int option; boolean_t s_arg = B_FALSE; boolean_t i_arg = B_FALSE; uint32_t interval = 0; show_link_state_t state; char *endp = NULL; state.ls_stats = B_FALSE; state.ls_parseable = B_FALSE; opterr = 0; while ((option = getopt_long(argc, argv, ":psi:", longopts, NULL)) != -1) { switch (option) { case 'p': state.ls_parseable = B_TRUE; break; case 's': if (s_arg) { (void) fprintf(stderr, gettext( "%s: the option -s cannot be specified " "more than once\n"), progname); usage(); } s_arg = B_TRUE; break; case 'i': if (i_arg) { (void) fprintf(stderr, gettext( "%s: the option -i cannot be specified " "more than once\n"), progname); usage(); } i_arg = B_TRUE; errno = 0; interval = (int)strtol(optarg, &endp, 10); if (errno != 0 || interval == 0 || *endp != '\0') { (void) fprintf(stderr, gettext("%s: invalid interval value" " '%d'\n"), progname, interval); exit(1); } break; case ':': (void) fprintf(stderr, gettext("%s: option requires a value '-%c'\n"), progname, optopt); exit(1); /*NOTREACHED*/ case '?': default: (void) fprintf(stderr, gettext("%s: unrecognized option '-%c'\n"), progname, optopt); exit(1); } } if (i_arg && !s_arg) { (void) fprintf(stderr, gettext("%s: the option -i " "can be used only with -s\n"), progname); usage(); } /* get link name (optional last argument) */ if (optind == (argc-1)) name = argv[optind]; else if (optind != argc) usage(); if (s_arg) { link_stats(name, interval); return; } if (name == NULL) { (void) dladm_walk(show_link, &state); } else { show_link(&state, name); } }