static void function (LIST * list, regexp * regex, flag_t flags) { char const * string; if (_anyset (flags, WHOM_B_USR)) { struct passwd * passwd; while ((passwd = getpwent ())) { string = regexspan (regex, passwd->pw_name); if ((string) && (! * string)) { listinsert (list, passwd->pw_name); } } } if (_anyset (flags, WHOM_B_GRP)) { struct group * group; while ((group = getgrent ())) { string = regexspan (regex, group->gr_name); if ((string) && (! * string)) { listinsert (list, group->gr_name); } } } return; }
static package bf_sort(Var arglist, Byte next, void *vdata, Objid progr) { /* sort(list) => sorts and returns list. sort({1,3,2}) => {1,2,3} */ /* returns E_TYPE is list is not all the same type */ Var sorted = new_list(0), tmp; Var e; int i, l; e.type=TYPE_NONE; for(i = 1; i <= arglist.v.list[1].v.list[0].v.num; i++) { e = var_ref(arglist.v.list[1].v.list[i]); l = find_insert(sorted, e); if(l == -10) { free_var(arglist); free_var(sorted); free_var(e); return make_error_pack(E_TYPE); } tmp = listinsert(var_ref(sorted), var_ref(e), l); free_var(sorted); sorted = var_ref(tmp); free_var(tmp); } free_var(arglist); free_var(e); return make_var_pack(sorted); }
int main() { int i, di; ELemType e, de; linklist *L = (linklist *)malloc(sizeof(linklist)); if (!L) return ERROR; printf("creat a linklist\n"); CreatList(L); printf("L = %d \n", L->next->data); display(L); //linklist *m; // m = L; //display(L); reverse(L); display(L); printf("please input the insert lo & elem:\n"); scanf("%d %d", &i, &e); listinsert(L, i, e); printf("please input the del number:\n"); scanf("%d", &di); listdel(L, di, &de); display(L); free(L); return 0; }
static int handle_end_array(void *ctx) { struct parse_context *pctx = (struct parse_context *)ctx; Var list = new_list(0); Var v; for (v = POP(pctx->top); (int)v.type > ARRAY_SENTINEL; v = POP(pctx->top)) { list = listinsert(list, v, 1); } PUSH(pctx->top, list); return 1; }
/* * listenqueue() * * Enqueue a new element at the end * of the list. * * listenque()/listdeque() * implements FCFS policy. * */ int listenque(struct list_ *h, struct list_ *e2) { assert(h && e2); /* before: h->e */ listinsert(h, h, e2); /* after: h->e->e2 */ return 0; }
/* * listpush() * * Push e at the front of the list * * H --> e --> e2 * */ int listpush(struct list_ *h, struct list_ *e2) { /* before: h->e */ listinsert(h, h->forw, e2); /* after: h->e2->e */ return 0; }
void main() {sqlist L; int i,j,k,b,n,e,m,a,cur_e,pre_e,next_e,s; initlist(L); cout<<"初始化后的基值地址:"<<L.elem<<" L.length=:"<<L.length<<" L.listsize=:"<<L.listsize<<endl; cout<<"新建一顺序表."<<endl; cout<<"当前表是否为空表"<<listempty(L)<<endl; cout<<"定义该线性表长度:"<<endl; cin>>a; cout<<"分别输入线性表的各个元素,按ENTER"<<endl; for(k=1;k<=a;k++){ cin>>j; i=listinsert(L,k,j);} for(b=1;b<=a;b++) cout<<L.elem[b-1]<<endl; listlength(L); cout<<"当前表长:"<<L.length<<endl; cout<<"输入要取的数的位置n(n<=a)"<<endl; cin>>n; getelem(L,n,e); //cout<<L.elem[n-1]<<endl; cout<<e<<endl; cout<<"与该数相等的的一个数的位序为:"<<locateelem(L,e,compare)<<endl; cout<<"输入要取前驱的数的位置m(<=a)"<<endl; cin>>m; getelem(L,m,cur_e); if(priorelem(L,cur_e,pre_e)) cout<<"cur_e的前驱为:"<<pre_e<<endl; else cout<<"该元素没前驱"<<endl; nextelem(L,cur_e,next_e); if(nextelem(L,cur_e,next_e)) cout<<"cur_e的后继为:"<<next_e<<endl; else cout<<"该元素没后继"<<endl; cout<<"奇数在前,偶数在后,并输出"<<endl; move(L); for(s=1;s<=a;s++) cout<<L.elem[s-1]<<endl; cout<<"输入要删元素的位序m(<=a)"<<endl; cin>>m; listdelete(L,m,e); cout<<"被删的元素为:"<<e<<endl; cout<<"删除元素后表长为"<<L.length<<endl; //listtraverse(L,visit); cout<<"置为空表"<<clearlist(L)<<endl; cout<<"销毁线性表"<<destroylist(L)<<endl; }
int Pass2_LinkingLoader_H(char* record, int* length,Linkedlist *RSymbol){ char *tmplength; listinit(RSymbol); // RSymbol :(Reference Number , Symbol) listinsert(RSymbol,copy(1,6,record)); // Rsymbol Name listinsertmore(RSymbol,"01"); // reference number tmplength = copy(13,18,record); *length = StringToHex(tmplength); return 0; }
int main() { int x[6]={3,6,5,2,8,9},a,c,d,e=8,g; bool b,f; sqlist *A; createlist(A,x,6); listinsert(A,4,1); listdelete(A,2,g); displist(A); a=listlength(A); b=getelem(A,3,c); d=locateelem(A,e); printf("%d\n",a); printf("%d\n",b); printf("%d\n",d); printf("%d\n",f); system("pause"); return 0; }
int Pass2_LinkingLoader_R(char *record, Linkedlist *RSymbol){ int recordLength,i,theNumberOfRSymbol; int necessaryBlank=0; record[strlen(record)-1] = '\0'; // remove line feed recordLength = strlen(record); necessaryBlank = 8-((recordLength-1)%8); for(i=0;i<necessaryBlank;i++){ // strcat Blank strcat(record," "); } theNumberOfRSymbol = (strlen(record))/8; /* store RSymbol in Linkedlist */ for(i=0;i<theNumberOfRSymbol;i++){ listinsert(RSymbol,copy(8*i+3,8*i+8,record)); // reference number listinsertmore(RSymbol,copy(8*i+1,8*i+2,record)); // Rsymbol Name } return 0; }
void listload (LIST * list, char const *file, char buffer [], size_t length) { FILE *fp; char *sp; if ((fp = efopen (file, "r")) != (FILE *) (0)) { while (fgetline (buffer, length, fp) != -1) { for (sp = buffer; isblank (*sp); ++sp); if (strchr ("#;\n", *sp) == (char *) (0)) { listinsert (list, sp); } } fclose (fp); } return; }
int main() { int x[]={32,42,334,22,67,89}; int a,c,d,f; bool b,e,g; linklist *A; createlistr(A,x,6); b=getelem(A,4,c); d=locateelem(A,67); listinsert(A,4,76); listdelete(A,2,f); displist(A); a=listlength(A); printf("%d\n",a); printf("%d\n",c); printf("%d\n",d); printf("%d\n",f); system("pause"); return 0; }
int Proutespline (Pedge_t *edges, int edgen, Ppolyline_t input, Ppoint_t *evs, Ppolyline_t *output) { #if 0 Ppoint_t p0, p1, p2, p3; Ppoint_t *pp; Pvector_t v1, v2, v12, v23; int ipi, opi; int ei, p2ei; Pedge_t *e0p, *e1p; #endif Ppoint_t *inps; int inpn; /* unpack into previous format rather than modify legacy code */ inps = input.ps; inpn = input.pn; #if 0 if (!(p2es = (p2e_t *) malloc (sizeof (p2e_t) * (p2en = edgen * 2)))) { prerror ("cannot malloc p2es"); abort (); } for (ei = 0, p2ei = 0; ei < edgen; ei++) { if (edges[ei].a.x == edges[ei].b.x && edges[ei].a.y == edges[ei].b.y) continue; p2es[p2ei].pp = &edges[ei].a; p2es[p2ei++].ep = &edges[ei]; p2es[p2ei].pp = &edges[ei].b; p2es[p2ei++].ep = &edges[ei]; } p2en = p2ei; qsort (p2es, p2en, sizeof (p2e_t), cmpp2efunc); elist = NULL; for (p2ei = 0; p2ei < p2en; p2ei += 2) { pp = p2es[p2ei].pp; #if DEBUG >= 1 fprintf (stderr, "point: %d %lf %lf\n", p2ei, pp->x, pp->y); #endif e0p = p2es[p2ei].ep; e1p = p2es[p2ei + 1].ep; p0 = (&e0p->a == p2es[p2ei].pp) ? e0p->b : e0p->a; p1 = (&e0p->a == p2es[p2ei + 1].pp) ? e1p->b : e1p->a; if (LT (p0, pp) && LT (p1, pp)) { listdelete (e0p), listdelete (e1p); } else if (GT (p0, pp) && GT (p1, pp)) { listinsert (e0p, *pp), listinsert (e1p, *pp); } else { if (LT (p0, pp)) listreplace (e0p, e1p); else listreplace (e1p, e0p); } } #endif /* generate the splines */ evs[0] = normv (evs[0]); evs[1] = normv (evs[1]); opl = 0; growops (4); ops[opl++] = inps[0]; if (reallyroutespline (edges, edgen, inps, inpn, evs[0], evs[1]) == -1) return -1; output->pn = opl; output->ps = ops; #if 0 fprintf (stderr, "edge\na\nb\n"); fprintf (stderr, "points\n%d\n", inpn); for (ipi = 0; ipi < inpn; ipi++) fprintf (stderr, "%f %f\n", inps[ipi].x, inps[ipi].y); fprintf (stderr, "splpoints\n%d\n", opl); for (opi = 0; opi < opl; opi++) fprintf (stderr, "%f %f\n", ops[opi].x, ops[opi].y); #endif return 0; }
void function (char const * path, char * file, size_t width, size_t count, bool index, flag_t flags) { DIR * dir; LIST list; listcreate (& list, _LISTSIZE); printf ("%s\n", path); if ((dir = opendir (path))) { struct dirent * dirent; struct stat statinfo; while (* file) { file++; } * file++ = PATH_C_EXTENDER; while ((dirent = readdir (dir))) { char const * sp = dirent->d_name; if (* sp == FILE_C_EXTENDER) { sp++; } if (* sp == FILE_C_EXTENDER) { sp++; } if (* sp == (char) (0)) { continue; } strcpy (file, dirent->d_name); if (lstat (path, & statinfo)) { error (0, errno, "%s", path); continue; } if (S_ISDIR (statinfo.st_mode)) { if (flags & (FIND_B_DIR)) { listinsert (& list, file); } continue; } if (S_ISLNK (statinfo.st_mode)) { if (flags & (FIND_B_LNK)) { listinsert (& list, file); } continue; } if (S_ISREG (statinfo.st_mode)) { if (flags & (FIND_B_REG)) { listinsert (& list, file); } continue; } } * -- file = (char) (0); closedir (dir); } listcolumn (& list, stderr, width, count, index); listdelete (& list); return; }