Пример #1
0
int main()
{
    int i, j,tmp;
    int a[N],b[N];
    for(i=10;;i++)
    {
        memset(a, 0, N*sizeof(int));
        format_long_num(i,a);
        sort_list(&a[1],a[0]);
        for(j=2;j<=MAX_NUM;j++)
        {
            tmp = i*j;
            memset(b, 0, N*sizeof(int));
            format_long_num(tmp,b);
            sort_list(&b[1],b[0]);

            if(memcmp(a,b, N*sizeof(int))!=0)
                break;
        }
        if(j==MAX_NUM+1)
        {
            printf("%d\n", i);
            break;
        }
    }
   
}
Пример #2
0
int		main()
{
  t_glist	*lst;
  t_glist	*clone;
  t_glist	*rev;
  /* t_elem	elem; */

  /* srand(time(0)); */
  /* elem.id = rand() % 10; */
  lst = init_list();
  printf("[+] Init list...\n");
  put_elements(lst, 10);
  show_list_content(lst);
  printf("[+] Sorting...\n");
  sort_list(lst, data_cmp);
  show_list_content(lst);
  printf("[+] Sorting opposite...\n");
  sort_list(lst, data_cmp_opp);
  show_list_content(lst);
  printf("[+] Will clone list...\n");
  clone = clone_list(lst);
  show_list_content(clone);
  printf("[+] Will rev list...\n");
  rev = get_rev(lst);
  show_list_content(rev);
  printf("[+] Will rm last elem from clone...\n");
  rm_last(clone);
  show_list_content(clone);
  printf("[+] Will rm first elem from clone...\n");
  rm_first(clone);
  show_list_content(clone);
  printf("[+] Will show list from end to start...\n");
  end_to_start(clone);
  return (0x0);
}
Пример #3
0
int main(int argc, const char *argv[])
{
    TContact_list contact_list = {contact_list.first = NULL, contact_list.last = NULL};
    get_dir();
    
    switch(get_mode(argc, argv)){
        case DEL:
            get_data(&contact_list);
            remove_from_list(&contact_list, atoi(argv[2]));
            save_csv(&contact_list);
            generate_html(&contact_list);
            free_list(&contact_list);
            break;
        case ADD:
            get_data(&contact_list);
            add_to_list(argv, &contact_list);
            sort_list(&contact_list);
            save_csv(&contact_list);
            generate_html(&contact_list);
            free_list(&contact_list);
            break;
        case LIST:
            get_data(&contact_list);
            sort_list(&contact_list);
            print_list(&contact_list);
            save_csv(&contact_list);
            generate_html(&contact_list);
            free_list(&contact_list);
            break;
        case SIN:
            get_data(&contact_list);
            print_single(&contact_list, atoi(argv[2]));
            free_list(&contact_list);
            break;
        case FIND:
            get_data(&contact_list);
            find_in_list(&contact_list, (char *)argv[2]);
            generate_html(&contact_list);
            free_list(&contact_list);
            break;
        case PLIST:
            get_data(&contact_list);
            sort_list(&contact_list);
            generate_plist(&contact_list);
            free_list(&contact_list);
            break;
        case DELN:
            get_data(&contact_list);
            delete_by_name(&contact_list, (char *)argv[2], (char *)argv[3]);
            save_csv(&contact_list);
            generate_html(&contact_list);
            free_list(&contact_list);
        default:
            handle_errors();
            return EXIT_FAILURE;
    }
    if(handle_errors() != EXIT_SUCCESS) return EXIT_FAILURE;
    else return EXIT_SUCCESS;
}
Пример #4
0
	//  Load the item lists from the file in players config directory
	//
	void List_Container::load(void)
	{
		loaded = true;
		saved_item_lists.clear();
		std::string fullpath = get_path_config() + std::string(filename);
		std::ifstream in(fullpath.c_str());
		if (!in)
			return;
		int revision;
		in >> revision;
		if (revision != FILE_REVISION)
		{
			LOG_ERROR("%s: %s [%s]\n", __FILE__, item_list_version_error_str, fullpath.c_str() );
			return;
		}
		while (!in.eof())
		{
			saved_item_lists.push_back(List());
			if (!saved_item_lists.back().read(in))
				saved_item_lists.pop_back();
		}
		in.close();
		sort_list();
		active_list = 0;
	}
Пример #5
0
// Desc : Remove a employee from list
// Params : head - The head node of list
// Return : None
void remove_employee(Node *head)
{
  Node* node;
  char emp_no[7];

  if(head->next == NULL)
  {
    printf("\n:: There is no employee!\n");
    return;
  }

  sort_list(head);
  print_list(head);

  printf("\n> Employee Number : ");
  gets(emp_no);
  fflush(stdin);

  node = find_node(head, emp_no);
  if(node)
  {
    remove_node(head, node);
    printf(":: Success!\n");
  }else{
    printf(":: The employee number does not exist!\n");
  }
}
Пример #6
0
	//  Load the item lists from the file in players config directory
	//
	void List_Container::load(void)
	{
		loaded = true;
		saved_item_lists.clear();
		std::string fullpath = get_path_config() + std::string(filename);
		std::ifstream in(fullpath.c_str());
		if (!in)
			return;
		int revision;
		in >> revision;
		if (revision != FILE_REVISION)
		{
			LOG_ERROR("%s: %s [%s]\n", __FILE__, item_list_version_error_str, fullpath.c_str() );
			LOG_TO_CONSOLE(c_red2, item_list_version_error_str);
			return;
		}
		bool logged_error = false;
		while (!in.eof())
		{
			saved_item_lists.push_back(List());
			if (!saved_item_lists.back().read(in))
			{
				if ((saved_item_lists.back().is_valid_format()) && !logged_error)
				{
					LOG_TO_CONSOLE(c_red2, item_list_format_error);
					logged_error = true;
				}
				saved_item_lists.pop_back();
			}
		}
		in.close();
		sort_list();
		set_active(initial_active_list);
	}
Пример #7
0
gpointer inquire_province(size_t offset)
{
    float result;
    Province *pp;
    gchar *str;
    struct datalist *headlist=NULL,*p=NULL,*q=NULL;
    for(pp=head_province;pp;pp=pp->next)
    {
        result=*(float*)((gpointer)pp+offset);
        str=pp->name;
        p=(struct datalist*)malloc(sizeof(struct datalist));
        *(char**)p->data=str;
        *(float*)(p->data+sizeof(char*))=result;
        if(!headlist)
        {
            headlist=p;
        }
        else
        {
            for(q=headlist;q->next;q=q->next);
            q->next=p;
        }
        p->next=NULL;
    }
    sort_list(&headlist,sizeof(char*));
    return headlist;
}
Пример #8
0
void sortStructTest() {
	struct node_t nodes[20];
	nodes[0].prev = NULL;
	nodes[0].next = &(nodes[1]);
	nodes[19].next = NULL;
	nodes[19].prev = &(nodes[19]);
	int i;
	for(i = 1; i < 19; i++) {
		nodes[i].prev = &(nodes[i-1]);
		nodes[i].next = &(nodes[i+1]);
	}
	for(i = 0; i < 20; i++) {
		nodes[i].data = i % 7;
	}
	
	struct list_t list;
	list.head = &(nodes[0]);
	list.tail = &(nodes[19]);
	
	sort_list(&list);
	
	struct node_t* iter = list.head;
	while(iter != NULL) {
		printIntEndline(iter->data);
		iter = iter->next;
	}
}
Пример #9
0
//查看列表
void print_list(list L)
{
    int page=1;
    char ch;
    int max_page=len_list(L)/NPAGE+(len_list(L)%NPAGE==0?0:1);
    for(;;)
    {
        CLS;
        //头列标记
        print_list_one_page(L,page);
        printf("\n==第 %d 页",page);
        if(page==max_page)printf(",尾页");
        printf("==\n");
        printf("使用“-”和“=”翻页,“s”排序,“0”回到主菜单\n");
        ch=getch();
        switch(ch)
        {
        case '-':
            if(page>1)
                --page;
            break;
        case '=':
            if(page<max_page)
                ++page;
            break;
        case '0':
            return;
            break;
        case 's':
            sort_list(L);
            page=1;
            break;
        }
    }
}
Пример #10
0
main() {
  list_t mylist;
  mylist.head = mylist.tail = NULL;
  node_t * old_node;
  node_t * rm_node;
  
  // list creation phase
  insert_at_front(8,  &mylist);
  rm_node = mylist.head;
  insert_at_front(5,  &mylist);
  insert_at_front(1,  &mylist);
  insert_at_front(12, &mylist);
  insert_at_front(3,  &mylist);
  insert_at_front(9,  &mylist);
  insert_at_front(7,  &mylist);
  print_list(&mylist);
  
  // list sort phase
  sort_list( &mylist);
  print_list(&mylist);

  // element removal phase
  remove_element( mylist.head, &mylist );
  remove_element( mylist.head, &mylist );
  remove_element( mylist.tail, &mylist );
  remove_element( rm_node, &mylist );
  print_list(&mylist);
}
Пример #11
0
/*
 * Builds the full neighborlist list from scratch for a particle
 * This is used for the initial build for all the particles, then for rebuilds
 * of moved particles
 *
 * arguments:
 *      particles:      The spatially decomposed particle information
 *      neighbor_list:  The particle's neighborlist
 *      x,y,z:          The indecies for the block which the particle belongs to
 *      array_index:    The index of the particle in the list
 */
void build_list_full(Particle* particles[XDiv][YDiv][ZDiv], Neighbor* neighbor_list, int x, int y, int z, int array_index){
    // Iterates through the buckets in in such a way that for every pair of particles which are
    // potential neighbors, one and only one of them will have to check the distance for that pair. This is done by,
    // if we are looking at particle p, only looking at particles further down in the array in the block containing p,
    // and only looking in a "forward" direction (that is, for each pair of blocks that are "across" from eachother around
    // the block containing p, we consider only of those blocks)

    
    int j, k;
    int index = 0;
    Particle p = particles[x][y][z][array_index];
    
    for (j = -1; j <= 1; ++j){ //y offset
        for (k = -1; k <= 1; ++k) { //z offset
            check_particles(particles, x+1, y+j, z+k, neighbor_list, p, &index);
        }
    }
    
    check_particles(particles, x, y+1, z+1, neighbor_list, p, &index);
    check_particles(particles, x, y+1, z  , neighbor_list, p, &index);
    check_particles(particles, x, y+1, z-1, neighbor_list, p, &index);
    check_particles(particles, x, y  , z+1, neighbor_list, p, &index);
    check_particles_center(particles, x, y, z, array_index, neighbor_list, p, &index);
    
    sort_list(neighbor_list);

}
Пример #12
0
int config_write(int level, const char *media) {
    logprintf(LOG_STACK, "%s(...)", __FUNCTION__);

    struct JsonNode *root = json_mkobject();
    FILE *fp;

    sort_list(0);
    struct config_t *listeners = config;
    while(listeners) {
        if(listeners->sync) {
            struct JsonNode *child = listeners->sync(level, media);
            if(child != NULL) {
                json_append_member(root, listeners->name, child);
            }
        }
        listeners = listeners->next;
    }

    /* Overwrite config file with proper format */
    if(!(fp = fopen(configfile, "w+"))) {
        logprintf(LOG_ERR, "cannot write config file: %s", configfile);
        return EXIT_FAILURE;
    }
    fseek(fp, 0L, SEEK_SET);
    char *content = json_stringify(root, "\t");
    fwrite(content, sizeof(char), strlen(content), fp);
    fclose(fp);
    json_free(content);
    json_delete(root);
    return EXIT_SUCCESS;
}
Пример #13
0
int config_parse(JsonNode *root) {
    logprintf(LOG_STACK, "%s(...)", __FUNCTION__);

    struct JsonNode *jconfig = NULL;
    unsigned short error = 0;

    sort_list(1);
    struct config_t *listeners = config;
    while(listeners) {
        if((jconfig = json_find_member(root, listeners->name))) {
            if(listeners->parse) {
                if(listeners->parse(jconfig) == EXIT_FAILURE) {
                    error = 1;
                    break;
                }
            }
        }
        listeners = listeners->next;
    }

    if(error == 1) {
        config_gc();
        return EXIT_FAILURE;
    } else {
        return EXIT_SUCCESS;
    }
}
Пример #14
0
void	count_alpha(int argc, char *argv[])
{
	int	i;
	int	k;
	int	lower_alpha[26] = {0};
	int	upper_alpha[26] = {0};
	int	alpha_count[26] = {0};

	i = 0;
	while (i < 26)
	{
		lower_alpha[i] = 97 + i;
		upper_alpha[i] = 65 + i;
		i++;
	}
	i = 0;
	while (argv[1][i])
	{
		k = 0;
		while (k < 26)
		{
			if (argv[1][i] == lower_alpha[k] || argv[1][i] == upper_alpha[k])
				alpha_count[k]++;
			k++;
		}
		i++;
	}
	sort_list(lower_alpha, upper_alpha,alpha_count, argv[1]);
}
Пример #15
0
/** Ejemplo de lista doblemente enlazada */
int main(int argc, char * argv[], char *arge[]) {

	int i;
	// Lista principal
	struct doubly_node *L = NULL;

	// Genera sets de datos
	random_init();
	for(i=0; i<10; i++)
		doubly_insert(&L, get_data());

	// Imprime la lista original
	print_list("Lista original", L);

	// Imprime la lista con algunos datos removidos
	crop_list(&L);
	print_list("Lista recortada", L);

	// Imprime la lista ordenada
	sort_list(L);
	print_list("Lista ordenada", L);

	// Imprime la lista con algunos datos ordenados
	doubly_insert_after( L->next, get_data());
	doubly_insert_before( L->next, get_data());
	print_list("Lista con elementos adicionales", L);

	// Libera memoria
	doubly_destroy(&L);

	return 0;
}
Пример #16
0
void chain_pair_alg_update_init(struct DotList *dots, int *num, struct kdnode *tree, struct perm_pt *p_pts, int size1, int size2, struct DotList *init_algns)
{
	struct slist *sorted;
	int i = 0;
	int num_lines = 0;
	int xval = 0, yval = 0;
	int w_sid = 0, w_fid = 0, h_sid = 0, h_fid = 0;
	int opt_id = -1;
	bool *is_x;

	is_x = (bool *) malloc(sizeof(bool));
	num_lines = *num;

	sorted = (struct slist *) ckalloc((*num) * sizeof(struct slist));

	if( num_lines > 0 ) sort_list(sorted, dots, num_lines);

	for( i = 0; i < num_lines; i++ )
	{
		opt_id = -1;
		if( dots[sorted[i].id].sign == DELETED )
		{
		}
		else
		{
			xval = dots[sorted[i].id].x.lower;
			if( dots[sorted[i].id].sign == 0 )
			{
				yval = dots[sorted[i].id].y.lower;
			}
			else 
			{
				yval = dots[sorted[i].id].y.upper;
			}	
			
			w_sid = find_id(dots, tree, size1, sorted[i].id, xval, yval, W_SID);
			w_fid = find_id(dots, tree, size1, sorted[i].id, xval, yval, W_FID);
			h_sid = find_id(dots, tree, size2, sorted[i].id, xval, yval, H_SID);
			h_fid = find_id(dots, tree, size2, sorted[i].id, xval, yval, H_FID);

			opt_id = find_opt_ch_alg(dots, num_lines, sorted[i].id, p_pts, w_sid, w_fid, h_sid, h_fid);
		}

		if( opt_id != -1 ) 
		{
			if( debug_mode == TRUE ) {
				printf("Combined: %d-%d,%d-%d\n", dots[opt_id].x.lower, dots[opt_id].x.upper, dots[opt_id].y.lower, dots[opt_id].y.upper);
				printf("%d-%d,%d-%d\n", dots[sorted[i].id].x.lower, dots[sorted[i].id].x.upper, dots[sorted[i].id].y.lower, dots[sorted[i].id].y.upper); 
			}

			mark_chain(dots, opt_id, sorted[i].id, init_algns);
			merging_step(dots, opt_id, sorted[i].id);
		}	
	}
	overwrite_dots(num, dots);

	free(sorted);
	free(is_x);
}
Пример #17
0
void add_to_list()
{
   if(head == NULL) {
      create_list();
   } else {
      sort_list();
   }
}
Пример #18
0
LOCAL	void	sort_list(
	NAME_LIST **files,
	int left,
	int right)
{
	int i, last;

	if (left >= right) return;
	swap(files,left,(left+right)/2);
	last = left;
	for (i = left+1; i <= right; ++i)
		if (in_order(files[i],files[left]) == -1)
			swap(files,++last,i);
	swap(files,left,last);
	sort_list(files,left,last-1);
	sort_list(files,last+1,right);
}
Пример #19
0
int main(int argc, char* argv[]) {
    int list[] = { 30, 1, 3, 6, 7, 8, 4, 16, 29, 10, 11, 12, 20, 5, 9, 23, 26,
                   22, 24, 13, 14, 17, 18, 19, 27, 28, 2, 25, TERMCHAR };
    int list_length = count(list);
    printf("Got a list of length: %d\n", list_length);
    print_list(list);
    sort_list(list);
    print_list(list);
}
Пример #20
0
	//	Rename the active list
	//
	void List_Container::rename_active(const char *name)
	{
		if (active_list >= size())
			return;
		saved_item_lists[active_list].set_name(name);
		sort_list();
		select_by_name(name);
		save();
	}
Пример #21
0
int main(void)
{
  /* Declare YOUR variables here ! */
  Slist mylist;
  int menu_choice;

  /* Seed to random generator and clear the screen.. */
  srand((unsigned int)time(NULL));

  if ((mylist = SLISTinit(my_destroy)) == NULL)
    {
      printf("\nFatal error... - bailing out!");
      SLISTdestroy(mylist);
      exit(-1);
    }

  /* Set match-callback into list structure.. */
  SLISTsetmatch(mylist, my_match);

  /* Populate the (empty) list.. */
  create_random_nodes(mylist, NR_OF_ITEMS);

  /* Enter menu loop... */
  do
    {
      menu_choice = menu(MAIN_MENU_ROW, 0, 5);

      switch (menu_choice)
        {
        case 1:
          ins_nodes(mylist);
          break;
        case 2:
          rem_nodes(mylist);
          break;
        case 3:
          search_node(mylist);
          break;
        case 4:
          sort_list(mylist);
          break;
        case 5:
          print_list(mylist);
          break;
        default:
          final_status(mylist);
          break;
        }
    }
  while (menu_choice); 

  /* ..and finally destroy the list. */
  prompt_and_pause("\n\nLet's tidy up and destroy the list..- Bye!");
  SLISTdestroy(mylist);

  return 0;
}
Пример #22
0
void main( ){

	int opt= 0;
	int p;
	process *proc;
	list *l;

	l= (list * ) malloc (sizeof(list));


	make_list(l);
	printf("\n\n\n");
	printf("\tTrabalho ED1 - Marcos Oleiro - Listas Simplesmente Encadeadas\n");
	printf("\n\n\n");
	while (opt != 3) {

		printf("1 - Adcionar Processos.\n");
		printf("2 - Listar Processos.\n");
		printf("3 - Sair.\n\n\n");

		printf("Digite sua opcao: ");
		scanf ("%d", &opt);
		printf("\n");
		switch (opt) {

			case 1:
				// process *proc= NULL ;
				printf("\n");
				proc = newProcess();
				printf("\n\n");
				add_process(l,proc);
				printf("ID: %d, Prioridade: %d, Horario: %d:%d:%d\n",proc->id, proc->priority,
					proc->h->hour,proc->h->minute,proc->h->second);
				proc = NULL;
				printf("\n\n");



			break;

			case 2:
				// printf("Opção 2.\n");
				// sort_priority(l);
				sort_list(l);
				print_list(l);

			break;

			case 3:
				// printf("Opção 3.\n");

			break;

		}
	}
}
Пример #23
0
// Desc : Print all the employee data
// Params : head - The head node of list
// Return : None
void retrieve_employee(Node *head)
{
  if(head->next == NULL)
  {
    printf("\n:: There is no employee!\n");
    return;
  }
  sort_list(head);
  print_list(head);
}
Пример #24
0
static void do_trace_mem(struct tracecmd_input *handle)
{
	struct pevent *pevent = tracecmd_get_pevent(handle);
	struct event_format *event;
	struct pevent_record *record;
	int missed_events = 0;
	int cpus;
	int cpu;
	int ret;

	ret = tracecmd_init_data(handle);
	if (ret < 0)
		die("failed to init data");

	if (ret > 0)
		die("trace-cmd mem does not work with latency traces\n");

	cpus = tracecmd_cpus(handle);

	/* Need to get any event */
	for (cpu = 0; cpu < cpus; cpu++) {
		record = tracecmd_peek_data(handle, cpu);
		if (record)
			break;
	}
	if (!record)
		die("No records found in file");

	ret = pevent_data_type(pevent, record);
	event = pevent_data_event_from_type(pevent, ret);

	common_type_field = pevent_find_common_field(event, "common_type");
	if (!common_type_field)
		die("Can't find a 'type' field?");

	update_kmalloc(pevent);
	update_kmalloc_node(pevent);
	update_kfree(pevent);
	update_kmem_cache_alloc(pevent);
	update_kmem_cache_alloc_node(pevent);
	update_kmem_cache_free(pevent);

	while ((record = tracecmd_read_next_data(handle, &cpu))) {

		/* record missed event */
		if (!missed_events && record->missed_events)
			missed_events = 1;

		process_record(pevent, record);
		free_record(record);
	}

	sort_list();
	print_list();
}
Пример #25
0
static node *sort_list(node *head) {
	node *n;
	
	for(n = head; n != NULL; n = n->next) {
		if(n->children != NULL) {
			n->children = sort_list(n->children);
		}
	}
	
	return merge_sort(head);
}
int main(void)
{
  List *list;
  char *array[] = {"San Marcos", "Holberton", "School", "California", "San Francisco", NULL};

  if (!(list = array_to_list(array)))
    return (1);
  print_list(list);
  sort_list(&list, &node_cmp);
  print_list(list);
  free_list(list);
  return (0);
}
Пример #27
0
	//	Add a new list
	//
	bool List_Container::add(const char *name)
	{
		saved_item_lists.push_back(List());
		if (saved_item_lists.back().set(name))
		{
			sort_list();
			save();
			select_by_name(name);
			return true;
		}
		saved_item_lists.pop_back();
		return false;
	}
Пример #28
0
void sort_list(list_t * mylist) {
  if (mylist->head == mylist->tail) {
	 return;
  }
  node_t *smallest = mylist->head, *trav;
  for (trav = smallest->next ; trav != NULL ; trav = trav->next) {
	 if (trav->data < smallest->data) {
		smallest = trav;
	 }
  }
  remove_element(smallest, mylist);
  sort_list(mylist);
  insert_element_after(smallest, NULL, mylist);
}
Пример #29
0
void s_pair_heap::sort_list(s_pair *& p) const
{
  if (p == NULL || p->next == NULL) return;
  s_pair *p1 = NULL;
  s_pair *p2 = NULL;
  while (p != NULL)
    {
      s_pair *tmp = p;
      p = p->next;
      tmp->next = p1;
      p1 = tmp;

      if (p == NULL) break;
      tmp = p;
      p = p->next;
      tmp->next = p2;
      p2 = tmp;
    }

  sort_list(p1);
  sort_list(p2);
  p = merge(p1, p2);
}
Пример #30
0
void sort_list(struct list_t * mylist) {
	if (mylist->head != mylist->tail) {
		struct node_t *smallest = mylist->head;
		struct node_t *trav;
		for (trav = smallest->next ; trav != NULL ; trav = trav->next) {
			if (trav->data < smallest->data) {
				smallest = trav;
			}
		}
		remove_element(smallest, mylist);
		sort_list(mylist);
		insert_node_after(smallest, NULL, mylist);
	}
}