int main(int argc, char* argv[]){
    if(argc == 5){
        request.siz = atoi(argv[3]);
        request.beg = atoi(argv[2]);
        if(argv[4][0] == 'b'){
            isWorst = false;
        }else{
            isWorst = true;
        }
    }else if(argc == 4){
        request.siz = atoi(argv[2]);
        request.beg = -1;
        printf("!\n");
        if(argv[3][0] == 'b'){
            isWorst = false;
        }else{
            isWorst = true;
        }
    }else{
        printf("EX0: match.exe free 12 20 b(release 20 bytes, begin at 12, using best-matching).\nEX1: match.exe malloc 28 w(allocate 28 bytes, using worst-matching)\n");
        exit(0);
    }
    
    int begin, size;
    Node* p = &head;
    FILE* in;
    if(!(in = fopen("stats.txt", "r"))){
        printf("Fail to acquire memory States!\n");
    }
    
    while(~fscanf(in, "%d %d", &begin, &size)){
        printf("%d %d\n", begin, size);
        Node* newNode = new Node();
        p->nxt = newNode;
        p->beg = begin;
        p->siz = size;
        newNode->beg = -1;
        newNode->siz = 0;
        newNode->nxt = NULL;
        p = p->nxt;
        blocks ++;
    }
    fclose(in);
    
    printf("We get:\n");
    show_list();
    
    if(request.beg != -1){
        free_mem();
    }else if(isWorst){
        malloc_worst();
    }else{
        malloc_best();
    }
        
    printf("Current Mem-states:\n");
    show_list();
    write_back();
    return 0;
}
Exemplo n.º 2
0
int main(){
	list_node guard_node; 
	create_list(&guard_node);
	insert_node(&guard_node,2);
	insert_node(&guard_node,3);
	insert_node(&guard_node,4);
	insert_node(&guard_node,5);
	show_list(&guard_node);
	delete_node(&guard_node,3);
	show_list(&guard_node);
	return 0;
}
Exemplo n.º 3
0
int main(int argc, char **argv)
{
    List *list = NULL;
    list = init_list();
    
    get_value(list, 10);
    show_list(list->head);

    sort_list_descend(list->head);
    show_list(list->head);

    destroy_list(list);
    return 0;
}
Exemplo n.º 4
0
int main()
{
	list l = from_string("[1], 2, [[3,4], 5], [[[]]], [[[6]]], 7, 8, []", 0, 0);

	printf("Nested: ");
	show_list(l);
	printf("\n");

	list flat = flatten(l, 0);
	printf("Flattened: ");
	show_list(flat);

	/* delete_list(l); delete_list(flat); */
	return 0;
}
Exemplo n.º 5
0
int			my_select(t_list *list, struct termios old)
{
  int			i;
  char			buff[2];

  i = 0;
  while (i < 1)
    {
      screen_clear();
      buff[0] = 0;
      buff[1] = 0;
      buff[2] = 0;
      show_list(list);
      if (read(0, buff, 3) == -1)
	{
	  my_putstr("Error: read failled");
	  return (0);
	}
      else
	if (get_buff(buff, &i, list, old) == -1)
	  return (0);
    }
  if (i == 2)
    show_selected(list);
  return (0);
}
Exemplo n.º 6
0
int main( void )
{
	LISTPTR first = NULL; /* head pointer */
	int i = 0;
	int ch;
	char trash[256]; /* to clear stdin buffer. */

	while ( i++ < 5 ) /* build a list based on 5 items given */
	{
		ch = 0;
		printf("\nEnter character %d, ", i);

		do
		{
			printf("\nMust be a to z: ");
			ch = getc(stdin); /* get next char in buffer */
			gets(trash); /* remove trash from buffer */
		} while((ch < 'a' || ch > 'z') && (ch < 'A' || ch > 'Z'));

		first = add_to_list( ch, first );
	}

	show_list( first ); /* Dumps the entire list */
	free_memory_list( first ); /* Release all memory */
	return 0;
}
Exemplo n.º 7
0
int main(void) {
	struct liste l;
	new_list(&l);
	add_first(1, &l);
	show_list(&l);

	printf( "#1\n" );
	add_tail(2, &l);
	add_first(-10, &l);
	show_list(&l);

	printf( "#2\n" );
	list_remove_tail(&l);
	show_list(&l);

	return 0;
}
Exemplo n.º 8
0
/*
 * 显示主界面
 */
static void show_main_window()
{
	/*
	 * 声明变量username
	 */
	extern char username[];

	clear_win();
	move_to(0, 0);
	printf("┌────────────────────────────────┬─────────────────────────────┐\n");
	printf("│  销售单号:                     │ 收银员:                     │\n");
	printf("├────────────────────────────────┼─────────────────────────────┤\n");
	printf("│  商品条码:                     │ 数  量:                     │\n");
	printf("├────────────────────────────────┴────────┬────────────────────┤\n");
	printf("│  序号 条码 商品名称 单价 折扣 数量 金额 │      提示信息      │\n");
	printf("├─────────────────────────────────────────┤                    │\n");
	printf("│                                         │                    │\n");
	printf("│                                         │                    │\n");
	printf("│                                         │                    │\n");
	printf("│                                         │                    │\n");
	printf("│                                         │                    │\n");
	printf("│                                         │                    │\n");
	printf("│                                         │                    │\n");
	printf("│                                         │                    │\n");
	printf("│                                         │                    │\n");
	printf("│   第   页 ←上一页→下一页↑上一项↓下一项  │                    │\n");
	printf("├─────────────────────────────────────────┴────────────────────┤\n");
	printf("│   F2删除商品明细  F3结账 F4撤单 F6挂单  F7取单 F8添加        │\n");
	printf("│   F9注销                                 时间:               │\n");
	printf("└──────────────────────────────────────────────────────────────┘\n");

	/*
	 * 显示销售单号
	 */
	move_to(14, 2);
	printf("%05d", cur_sale->sale_num);

	/*
	 * 显示销售员
	 */
	move_to(44, 2);
	printf("%s", username);

	/*
	 * 显示商品列表
	 */
	show_list();

	/*
	 * 显示页码
	 */
	show_page_number();

	/*
	 * 显示错误提示
	 */
	show_error_tips();
}
Exemplo n.º 9
0
main()
{
//	head = malloc(sizeof(node));
//	head->data = 10;
//	head->next = head->prev = NULL;
	insert_tail(20);
	insert_tail(30);
	show_list(head);
}
Exemplo n.º 10
0
struct commit_list *find_bisection(struct commit_list *list,
					  int *reaches, int *all,
					  int find_all)
{
	int nr, on_list;
	struct commit_list *p, *best, *next, *last;
	int *weights;

	show_list("bisection 2 entry", 0, 0, list);

	/*
	 * Count the number of total and tree-changing items on the
	 * list, while reversing the list.
	 */
	for (nr = on_list = 0, last = NULL, p = list;
	     p;
	     p = next) {
		unsigned flags = p->item->object.flags;

		next = p->next;
		if (flags & UNINTERESTING)
			continue;
		p->next = last;
		last = p;
		if (!(flags & TREESAME))
			nr++;
		on_list++;
	}
	list = last;
	show_list("bisection 2 sorted", 0, nr, list);

	*all = nr;
	weights = xcalloc(on_list, sizeof(*weights));

	/* Do the real work of finding bisection commit. */
	best = do_find_bisection(list, nr, weights, find_all);
	if (best) {
		if (!find_all)
			best->next = NULL;
		*reaches = weight(best);
	}
	free(weights);
	return best;
}
Exemplo n.º 11
0
int
main(void)
{
	int opt, err, data1, data2;
	struct linked_list *list;

	list = malloc(sizeof(struct linked_list));
	if (list == NULL)
		return -1;
	list->first = NULL;

	do {
		printf("1 - add beginning\n2 - del beginning\n3 - add after\n"
			"4 - del after\n5 - show list\n0 - exit\n");
		scanf("%d", &opt);
		switch (opt) {
			case 0:
				free_list(list);
				break;
			case 1:
				printf("add beginning, data: ");
				scanf("%d", &data1);
				err = node_create_beginning(list, data1);
				if (err)
					print_error(err);
				break;
			case 2:
				printf("del beginning...\n");
				err = node_destroy_beginning(list);
				if (err)
					print_error(err);
				break;
			case 3:
				printf("add after data: ");
				scanf("%d", &data1);
				printf("new data: ");
				scanf("%d", &data2);
				err = node_create_after(list, data1,
					data2);
				if (err)
					print_error(err);
				break;
			case 4:
				printf("del after data: \n");
				scanf("%d", &data1);
				err = node_destroy_after(list, data1);
				if (err)
					print_error(err);
				break;
			case 5:
				show_list(list);
				break;
		}
	} while (opt);
	return 0;
}
Exemplo n.º 12
0
int main() {
    node *list = NULL;

    for (int i=0; i<10; i++) {
        node *n = new node;
        n->next = list;
        n->data = i;
        list = n;
    }

    std::cout << "As built: ";
    show_list(list);

    list = reverse(list);

    std::cout << "Reversed: ";
    show_list(list);
    return 0;
}
Exemplo n.º 13
0
int main (void) {
	char 	data[20] ;
	Node 	head = {0,NULL}  ;

	fgets(data , sizeof (data) , stdin) ;
	data[strlen(data)-1] = 0  ;

	create_list (&head , data) ;
	show_list (&head);

	int 	k ;

	scanf ("%d",&k) ;
	del_kth_node (&head , k);
	show_list (&head) ;
	destory_list (&head) ;

	return 0 ;
}
Exemplo n.º 14
0
int main()
{
	int ret, len;

	Node *single_linked_list;
	single_linked_list = create_list(3);
	ret = show_list(single_linked_list);

	//len = list_lenth(single_linked_list);
	//printf("the length of the list is %d\n", len);

	//single_linked_list = delete_node(single_linked_list, 3);
	//single_linked_list = insert_node(single_linked_list, 4);
	//single_linked_list = sort_node(single_linked_list);
	single_linked_list = reverse_node(single_linked_list);
	ret = show_list(single_linked_list);

	return 0;
}
Exemplo n.º 15
0
//主函数-各个函数的测试
int main(int argc, char ** argv)
{
    int i = 0;
    List_head head = NULL;
    head = init_list();
    List_node *node = create_node();
 
    printf("\n头部插入:\n"); 
    for(i = 0 ; i < seed ; i++ )
    {
        push_front(head,rand()%100);
    }
    show_list(head);                   
    
    printf("\n尾部插入:\n"); 
    for(i = 0 ; i < seed ; i++ )
    {
        push_back(head,rand()%100);
    }
    show_list(head);                   

    printf("\n头部删除:\n"); 
    pop_front(head);
    show_list(head);                 
  
    printf("\n尾部删除:\n"); 
    pop_back(head);
    show_list(head);                 
   
    printf("\n插入节点:\n"); 
    insert_node(head, 3, 100);
    show_list(head);                 
    
    find_node(head, 77,&node);

    printf("\n升序排序:\n");
    sort_list_ascend(head);
    show_list(head);                 

    printf("\n降序排序:\n");
    sort_list_descend(head);
    show_list(head); 
               
    printf("\n修改节点数据:\n");
    node = head->next->next; 
    modify_node(node, 777);
    show_list(head); 
    
    printf("\nthe length of this list :%d\n",get_list_length(head));
    
    destroy_list(&head);
    return 0;
}
Exemplo n.º 16
0
int main(int argc, char *argv[])
  {
  if (argc != 3 && argc != 2)
    {
    fprintf(stderr,"bomcmp a [b]\n");
    return -1;
    }

  /* Load them */
  struct assy *a = load(argv[1],1);
  struct assy *b = load(argv[2],0);

  if (!b)
    {
    /* Just list */
    if (a)
      {
      show_assy(a, 0);
      return 0;
      }
    else
      {
      fprintf(stderr,"No BOM loaded\n");
      return -1;
      }
    }

  /* Compare each assy */
  printf("Changed parts\n");
  cmp_assy(a,a,b,b,0,"");

  printf("\nAdded parts\n");
  show_list(alist,1);

  printf("\nDeleted parts\n");
  show_list(dlist,0);

  return 0;
  }
Exemplo n.º 17
0
// Main Part
int main(void)
{
  // Fuege ein paar Knoten hinzu
  insert_node("foo");
  insert_node("bar");
  insert_node("bla");

  // Loesche einen Knoten
  delete_node("bar");

  // Gib die Liste aus
  show_list();

  return 0;
}
Exemplo n.º 18
0
static int hs_do_list_out(User * u)
{
    char *key;

    key = moduleGetLastBuffer();
    if (!key)
        return MOD_CONT;

    if (stricmp(key, "+req") != 0)
        return MOD_CONT;

    show_list(u);

    return MOD_CONT;
}
Exemplo n.º 19
0
/*
 * Function for writing to my proc entry
 */
int my_proc_write(struct file *file, const char __user * buffer,
		  unsigned long count, void *data)
{
	char *str;
	char command[20];
	int val = 0;
	str = kmalloc((size_t) count, GFP_KERNEL);
	if (copy_from_user(str, buffer, count)) {
		kfree(str);
		return -EFAULT;
	}

	sscanf(str, "%s %d", command, &val);
#ifdef DEBUG
	printk("First Arguement %s\n", command);
	printk("Second Argument %d\n", val);
#endif

	if (!strcmp(command, "push")) {
		/* push node */
		printk(KERN_INFO "Pushing data on stack %d\n", val);
		todo_add_entry(val);
	}

	if (!strcmp(command, "pop")) {
		/* Delete Node */
		printk(KERN_INFO "popping data from stack%d\n", val);
		if (delete_node(val)) {
			printk(KERN_INFO "pop failed \n");
		}
	}

	if (!strcmp(command, "print")) {
		/* Print the linked list */
		printk(KERN_INFO "Printing the stack top-to-bottom\n");
		show_list();
	}

	if (!strcmp(command, "peek")) {
		/* Destroy the linked list */
		printk("Peeking the top of the stack linked list\n");
		destroy();

	}

	kfree(str);
	return count;
}
Exemplo n.º 20
0
int
main(int argc, char *argv[])
{
    LL *head = NULL;

    if (argc != 2)
    {
        fprintf(stderr, "Usage: ./a.out string");
        return EXIT_FAILURE;
    }

    reserve(&head, argv[1]);
    show_list(head);

    return EXIT_SUCCESS;
}
Exemplo n.º 21
0
void show_list(list l)
{
	int i;
	if (!l) return;
	if (!l->is_list) {
		printf("%d", l->ival);
		return;
	}

	printf("[");
	for (i = 0; i < l->ival; i++) {
		show_list(l->lst[i]);
		if (i < l->ival - 1) printf(", ");
	}
	printf("]");
}
Exemplo n.º 22
0
void show_hashlist(struct session *ses, struct hashtable *h, const char *pat, const char *msg_all, const char *msg_none)
{
    struct listnode *templist;

    if (!*pat)
    {
        tintin_printf(ses, msg_all);
        templist=hash2list(h, "*");
    }
    else
        templist=hash2list(h, pat);
    show_list(templist);
    if (*pat && !templist->next)
        tintin_printf(ses, msg_none, pat);
    zap_list(templist);
}
Exemplo n.º 23
0
void container_look_hook(const char *info) {
  OBJ_DATA *obj = NULL;
  CHAR_DATA *ch = NULL;
  hookParseInfo(info, &obj, &ch);

  if(objIsType(obj, "container") && !containerIsClosed(obj)) {
    LIST *vis_contents = find_all_objs(ch, objGetContents(obj), "", 
				       NULL, TRUE);
      // make sure we can still see things
      if(listSize(vis_contents) > 0) {
	send_to_char(ch, "It contains:\r\n");
	show_list(ch, vis_contents, objGetName, objGetMultiName);
      }
      deleteList(vis_contents);
  }
}
Exemplo n.º 24
0
void cesar_cipher_menu() {

    // initialisation des variables

    char str[400]; // la phrase à crypter
    list node = NULL; // la liste chainée
    int i, choice, key; // le compteur, le choix, la clé
    srand(time(NULL)); // préparation de la fonction random

    //  Présentation

    printf("Cryptage - Cesar : \n\n");
    printf("Veuillez saisir votre phrase a crypter : ");
    S_GETS(str);

    // Mise en place de la liste chainée

    for(i=0; i<strlen(str); i++) add_new_list(&node,&str[i],i);

    // Menu du choix de la clé

    printf("\n\n1 - Cle connue \n");
    printf("2 - Cle inconnue \n\n");
    s_scanf(&choice,1,2);

    if(choice == 1) {
        printf("Veuillez saisir votre cle (valeur entiere) : ");
        SAISIE(key); // clé saisie manuellement
        cesar_cipher(&node,&key); // Algo de chiffrage
    } else if(choice == 2) {
        key = RAND(); // clé random
        cesar_cipher(&node,&key); // Algo de chiffrage random
    }

    // On met la liste dans une chaine de caractère

    printf("Phrase cryptee : ");
    show_list(node);

    // La petite phrase d'avertissement

    printf("\n\nVeuillez notez votre phrase... \n");
    printf("\n");

    // Vidage de la mémoire
    free_list(&node);
}
Exemplo n.º 25
0
static void render()
{
    if (about_is_show)
    {
        return;
    }
	else if (visualization_isopen)
	{
		show_visualization(0, 0);
        show_processbar<79>(24, 0);
		return;
	}    
	show_list();
	show_processbar<80>(20, 0);
	show_help(21, 0);
    show_volume(21, 40);
}
Exemplo n.º 26
0
void STACKS(stk *head) {

	int option = 1;
	int chose;

	while (option) {
		system("CLS");

		printf("             STACKS\n");
		printf("--------------------------------\n");
		printf("	1. PUSH \n");
		printf("	2. POP\n");
		printf("	3. SHOW MAX\n");
		printf("	4. SHOW MIN\n");
		printf("	5. SHOW\n");
		printf("	6. BACK TO MAIN\n");
		printf("	Insert you choice : ");
		scanf("%d", &chose);

		switch (chose) {
		case 1:
			push_back(head);
			break;
		case 2:
			pop_back(head);
			break;
		case 3:
			get_max(head);
			break;
		case 4:
			get_min(head);
			break;
		case 5:
			show_list(head);
			break;
		case 6:
			main();
		default:
			printf("Wrong choice ! \n");
			Sleep(2000);
			break;
		}
	}
}
Exemplo n.º 27
0
void parse_sub(char *arg)
{
  char left[BUFFER_SIZE], right[BUFFER_SIZE], result[BUFFER_SIZE];
  struct listnode *mysubs, *ln;
  mysubs=common_subs;
  arg=get_arg_in_braces(arg, left,STOP_SPACES);
  arg=get_arg_in_braces(arg, right,WITH_SPACES);

  if(!*left) {
    tintin_puts2(rs::rs(1166));
    show_list(mysubs);
  }

  else if(*left && !*right) {
    if ((ln=search_node_with_wild(mysubs,left))!=NULL) {
      while((mysubs=search_node_with_wild(mysubs, left))!=NULL) {
        shownode_list(mysubs);
      }
    }
    else
      if (mesvar[MSG_SUB])
        tintin_puts2(rs::rs(1167));
  }

  else {
    if((ln=searchnode_list(mysubs, left))!=NULL) {
      deletenode_list(mysubs, ln);
      subnum--;
    }
    insertnode_list(mysubs, left, right, "0", ALPHA);
    subnum++;
    if (strcmp(right,".")!=0)
      sprintf(result, rs::rs(1168),right,left);
    else
      sprintf(result, rs::rs(1169), left);
    if (mesvar[MSG_SUB])
      tintin_puts2(result);
  }
}
Exemplo n.º 28
0
Arquivo: 16.c Projeto: artfly/OS-II
int main(int argc, char * argv[]) {
	char buff[STRLEN];
	pthread_t thread;
	int code;
	pthread_mutexattr_t attr;
	pthread_mutexattr_init(&attr);
    pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_ERRORCHECK);
    pthread_mutex_init(&mutex, &attr);
    code = pthread_create(&thread, NULL, sort_list, (void *)head);
    if (code != 0) {
        char buf[256];
        strerror_r(code, buf, sizeof buf);
        fprintf(stderr, "%s: creating thread: %s\n", argv[0], buf);
        exit(1);
    }

	while(1) {
		if (!fgets(buff, STRLEN, stdin)) {
			exit(EXIT_FAILURE);
		}
		size_t l = strlen(buff);
		if (l != 1 || buff[l - 1] != '\n') {
			node_t * node = (node_t *) malloc(sizeof(node_t));
			node->str = malloc(sizeof(char) * STRLEN);
			strncpy(node->str, buff, sizeof(char) * (l-1));
			pthread_mutex_lock(&mutex);
			head = add_node(node, head);
			pthread_mutex_unlock(&mutex);
		}
		else {
			pthread_mutex_lock(&mutex);
			show_list(head);
			pthread_mutex_unlock(&mutex);
		}
	}

	exit(EXIT_SUCCESS);
}
Exemplo n.º 29
0
void antisubstitute_command(const char *arg, struct session *ses)
{
    char left[BUFFER_SIZE];
    struct listnode *myantisubs, *ln;

    myantisubs = ses->antisubs;
    arg = get_arg_in_braces(arg, left, 1);

    if (!*left)
    {
        tintin_puts("#THESE ANTISUBSTITUTES HAS BEEN DEFINED:", ses);
        show_list(myantisubs);
    }
    else
    {
        if ((ln = searchnode_list(myantisubs, left)) != NULL)
            deletenode_list(myantisubs, ln);
        insertnode_list(myantisubs, left, left, 0, ALPHA);
        antisubnum++;
        if (ses->mesvar[MSG_SUBSTITUTE])
            tintin_printf(ses, "Ok. Any line with {%s} will not be subbed.", left);
    }
}
Exemplo n.º 30
0
int			set_env(t_plist *plist, char **cmd, char **env)
{
  char			*new_env;

  (void)env;
  new_env = NULL;
  if (cmd[1] == NULL)
    {
      show_list(plist, NULL, NULL);
      return (0);
    }
  if (cmd[2] == NULL)
    return (set_env_nothing(plist, cmd));
  if (check_env(plist, cmd) == -1)
    {
      new_env = my_strcat(new_env, cmd[1], -1, -1);
      new_env = my_strcat(new_env, "=", -1, -1);
      new_env = my_strcat(new_env, cmd[2], -1, -1);
      env_to_list(plist, new_env);
    }
  free(new_env);
  return (0);
}