Esempio n. 1
0
main()
{
//	head = malloc(sizeof(node));
//	head->data = 10;
//	head->next = head->prev = NULL;
	insert_tail(20);
	insert_tail(30);
	show_list(head);
}
Esempio n. 2
0
File: 1main.c Progetto: huaweili/esd
int main(){
	init();
	insert_tail(1);
	insert_tail(5);
	insert_tail(9);
	insert_in_order(7);
	insert_in_order(13);
	printf("有效数据个数是%d\n",size());
	for_each(print_cb,NULL);
	deinit();
	return 0;
}
Esempio n. 3
0
int main(int argc, char **argv)
{
    node_t *l1 = NULL;
    node_t *l2 = NULL;
    node_t *n;
    
    n = (node_t *)malloc(sizeof(node_t));
    n->val = 0;
    insert_tail(&l1, n);
    
    n = (node_t *)malloc(sizeof(node_t));
    n->val = 1;
    insert_tail(&l1, n);
    
    n = (node_t *)malloc(sizeof(node_t));
    n->val = 2;
    insert_tail(&l1, n);
    
    n = (node_t *)malloc(sizeof(node_t));
    n->val = 3;
    insert_tail(&l1, n);
    
    n = (node_t *)malloc(sizeof(node_t));
    n->val = 4;
    insert_tail(&l1, n);
    
    n = (node_t *)malloc(sizeof(node_t));
    n->val = 5;
    insert_tail(&l1, n);
    
    n = (node_t *)malloc(sizeof(node_t));
    n->val = 6;
    insert_tail(&l1, n);
    
    n = (node_t *)malloc(sizeof(node_t));
    n->val = 7;
    insert_tail(&l1, n);
    
    n = (node_t *)malloc(sizeof(node_t));
    n->val = 8;
    insert_tail(&l1, n);
    
	n = (node_t *)malloc(sizeof(node_t));
    n->val = 9;
    insert_tail(&l1, n);

    print_list(l1);

	printf("After:\n");
	node_t *ret = reverse_k_nodes(l1, 3);
	print_list(ret);
}
Esempio n. 4
0
/* program function that executes automatically */
int main(int argc, char *argv[]){
    
    /* create a new Linked List, insert a value */
    LinkedList *newList;
    newList = insert_tail(newList, 1);
    newList = insert_tail(newList, 3);
    newList = insert_tail(newList, 5);
    
    
    /*  print all the elements in the Linked List    */
    print(newList);
    
    return 0;
}
Esempio n. 5
0
struct l1 *insert(int key) {
  if(head == NULL) {
    head = (struct l1*) malloc(sizeof(struct l1));
    head->key = key;
    return head;
  }
  struct l1 *p = head;
  struct l1 *prev = NULL;
  while((p->key < key) && (p->next != NULL)) {
    prev = p;
    p = p->next;
  }
  if(prev == NULL) {
    struct l1*n = insert_head(key);
    return n;
  }
  if(p->next == NULL) {
    struct l1 *n = insert_tail(key);
    return n;    
  }
  struct l1 *n = (struct l1*) malloc(sizeof(struct l1));
  n->key = key;
  prev->next = n;
  n->next = p;
  return n;
}
Esempio n. 6
0
void coro_ready(coroutine* coro)
{
    //ASSERT(coro->status == M_FREE || coro->status == M_RUN);
    ASSERT(coro->status != M_EXIT);
    coro->status = M_READY;
    insert_tail(&coro->sched->wait_sched_queue, coro);
}
Esempio n. 7
0
int main() {
  insert_head(3);
  insert_tail(4);
  insert(2);
  insert(1);
  insert(5);
  print_l1();
  return 0;
}
Esempio n. 8
0
int s_add(list *l, student *s) {
    node *tmp=new_node();
    int ret;
    tmp->data=s;

    if((ret=s_check(l, s))==0) {
        insert_tail(l,tmp);
    }

    return ret; // student is added successfully
}
Esempio n. 9
0
int add_word(link p)
{

	link s;
	s = malloc(sizeof(*s));
	s->words = p->words;
	s->words.freq = 1;

	insert_tail(s, &myhead,&mytail);
	return 0;
}
Esempio n. 10
0
void load_file(char *filename)
{
    FILE *fp = NULL;

    printf("loading file %s\n", filename);
    fp = fopen(filename, "r");
    if (NULL == fp)
    {
        fprintf(stderr, "open file error: %s\n", strerror(errno));
        exit(-1);
    }

    int i = 0;
    while(1)
    {
        int ret;
        char buf[256] = "";
        char *p = NULL;
        link s = NULL;

        p = fgets(buf, 256, fp);
        if(p == NULL)
            break;

        s = malloc(sizeof(*s));
        ret = sscanf(buf, "%s %s %d %s %s %s %s %s %s\n",
                     s->student.name,
                     s->student.cname,
                     &s->student.age,
                     s->student.gender,
                     s->student.native,
                     s->student.mobile,
                     s->student.qq,
                     s->student.email,
                     s->student.hobby);

        // if(p == NULL)
        //   break;

        insert_tail(s);
        students[i] = s;
        i++;

        // printf("ret = %d\n", ret);
        // printf("line : %d, buf: <%s>\n", i, buf);

    }

    num = i;
    printf("all students is %d\n", num);

    return ;
}
Esempio n. 11
0
int main()
{
	node* list = new node();
	for (int i = 0; i < 5; ++i)
	{
		insert_tail(list, i);
	}
	printList(list);
	node* reverseList = reverse(&list);
	printList(reverseList);

	printList(list);
	printf("hello");
}
Esempio n. 12
0
AList_WS* new_list_mult_data(int data_count, ...) {

	AList_WS* new_list = new_list_size((size_t)data_count);
	assert(new_list != NULL /* ** OUT OF MEMORY ** */);

	va_list data;
	va_start (data, data_count);          
  	for(int i=0;i<data_count;++i) {
  		double temp = va_arg(data, double);
  		insert_tail(new_list, temp);
  	}     
  	va_end(data);

  	return new_list;
}
Esempio n. 13
0
void load_file(char *filename)
{
    FILE *fp;

    printf("loading file %s\n", filename);
    fp = fopen(filename, "r");

    int i = 0;
    while(1)
    {
        int ret;
        char buf[256] = "";
        char *p;
        link s = NULL;

        p = fgets(buf, 256, fp);
        if(p == NULL)
            break;

        s = malloc(sizeof(*s));
        ret = sscanf(buf, "%s %s %d %s %s %s %s %s %s",
                s->student.name,
                s->student.cname,
                &s->student.age,
                s->student.gender,
                s->student.native,
                s->student.mobile,
                s->student.qq,
                s->student.email,
                s->student.hobby);

        insert_tail(s);
        students[i] = s;
        i++;
    }

    num = i;
    printf("all students num is %d\n", num);

    return;
}
Esempio n. 14
0
int load_file(char *filename, link *p, link *q)
{
	FILE *fp;
	fp = fopen(filename,"r");
	if (fp == NULL)
		return 1;
	while(1)	
	{
	char *t = NULL;
	char buf[1024] = "";
		link s = NULL;

		t = fgets(buf, 1024, fp);
		buf[strlen(buf) - 1] = '\0';
		if (t == NULL)
			break;

		s = malloc(sizeof(*s));
		sscanf(buf,"%s",s->words.word);

		t = fgets(buf, 1024, fp);
		buf[strlen(buf) - 1] = '\0';
		strcpy(s->words.trans,buf);

		//t = sscanf(buf, 1024, fp);
/*if(strcmp((char *)p,"myhead") == 0)
{
		t = fgets(buf, 1024, fp);
		buf[strlen(buf) - 1] = '\0';
		s->words.freq = atoi(buf);
}*/
//经函数传进来的p是一个地址
		insert_tail(s, p, q);
	};
	return 0;
}
Esempio n. 15
0
int main(int argc, char **argv) {
  int choix=0;
  int value=0;

  printf("%s",menu);
  fflush(stdout);

  while(1) {
    fflush(stdin);
    choix = getchar();
    printf("\n");

    switch(choix) {
    case 'T' :
    case 't' :
      printf("Valeur du nouvel element ? ");
      scanf("%d",&value);
      if (insert_head(&la_liste,value)!=0) {
	printf("Erreur : impossible d'ajouter l'element %d\n",value);
      };
      break;

    case 'Q' :
    case 'q' :
      printf("Valeur du nouvel element ? ");
      scanf("%d",&value);
      if (insert_tail(&la_liste,value)!=0) {
		printf("Erreur : impossible d'ajouter l'element %d\n",value);
      };
      break;


    case 'F' :
    case 'f' :
		printf("Index de l'element a rechercher ? ");
		scanf("%d", &value);
		list_elem_t* result = find_element(la_liste, value);
		if(result != NULL)
			printf("La valeur de l'element numero %d est %d\n", value, result->value);
		else
			printf("Erreur, l'element numero %d n'existe pas\n", value);
      break;



    case 's' :
    case 'S' :
      printf("Valeur de l'element a supprimer ? ");
	  scanf("%d", &value);
	  if(remove_element(&la_liste, value) != 0)
		printf("Erreur, aucun element ne possede la valeur %d\n", value);
	  else
		printf("L'element de valeur %d a ete supprime avec succes\n", value);	
      break;


    case 'r' :
    case 'R' :
      printf("Renversement des elements de la liste.\n");
	  reverse_list(&la_liste);
      break;


    case 'x' :
    case 'X' :
      return 0;

    default:
      break;
    }
    print_list(la_liste);

    if (nb_malloc!=list_size(la_liste)) {
	printf("\nAttention : il y a une fuite memoire dans votre programme !\n");
	printf("la liste contient %d element, or il y a %d element vivant en memoire !\n",list_size(la_liste),nb_malloc);
    }
    getchar(); // pour consommer un RC et eviter un double affichage du menu !
    printf("%s\n",menu);
  }
  return 0;
}
Esempio n. 16
0
void init_menu_insert(AList_WS* list) {
	for (int i = 0; i < 3; ++i)
		printf("%s\n", MAIN_MENU[i]);

	printf("\ta. Insert at Head\n");
	printf("\tb. Insert at Tail\n");
	printf("\tc. Insert at position Next to an index\n");
	printf("\td. Insert at position Prev to an index\n");
	printf("\te. Go Back\n");

	for (int i = 3; i < 8; ++i)
		printf("%s\n", MAIN_MENU[i]);

	printf("\vPLease enter option: ");

	char* input = (char*)(malloc(100));
	memset(input, '-', 100);
	scanf("%s", input);
	char ch = input[0];

	if (isdigit(input[0]) && isdigit(input[1]))
		ch = 'X';

	switch (ch) {

	case '1':
	case 'a':
	case 'H':
	{
		printf("Please enter the value you want to insert: ");
		double data;
		scanf("%lf", &data);
		insert_head(list, data);
		break;
	}

	case '2':
	case 'b':
	case 'T':
	{
		printf("Please enter the value you want to insert: ");
		double data;
		scanf("%lf", &data);
		insert_tail(list, data);
		break;
	}

	case '3':
	case 'c':
	case 'N':
	{
		printf("Please enter the value you want to insert: ");
		double data;
		scanf("%lf", &data);
		printf("Please enter the position");
		size_t pos;
		scanf("%lu", pos);
		insert_next(list,pos,data);
		break;
	}

	case '4':
	case 'd':
	case 'P':
	{
		printf("Please enter the value you want to insert: ");
		double data;
		scanf("%lf", &data);
		printf("Please enter the position");
		size_t pos;
		scanf("%lu", pos);
		insert_prev(list,pos,data);
		break;
	}

	case '5':
	case 'e':
	case 'B':
		break;

	default:
		printf("Please enter a valid choice.\n\n");
		init_menu_insert(list);
	}
}
Esempio n. 17
0
	void relink_tail(list *_list) { erase(); insert_tail(_list); }
Esempio n. 18
0
	void insert_tail(list &_list) { insert_tail(&_list); }