コード例 #1
0
 ~blocking_cached_stack2() {
     delete_head();
     T* e = m_stack.load();
     if (e && e != m_dummy) {
         consume_stack();
         delete_head();
     }
     delete m_dummy;
 }
コード例 #2
0
ファイル: main.c プロジェクト: White-Soot/c-c-
int main()
{
    int ile,i,var;

    char command[16];

   scanf("%u ", &ile);
   for(i= 0; i< ile;i++){
       scanf("%s %u", &command, &var);

       if(strcmp(&command,"insert")==0){
           append(var);
       }else if(strcmp(&command,"delete_head")==0){
           delete_head();
       }else if(strcmp(&command,"delete_tail")==0){
         delete_tail();
       }else if(strcmp(&command,"print")==0){
            show();
       }else if(strcmp(&command,"count")==0){
            count();
       }else if(strcmp(&command,"insert_head")==0){
            add_new_head(var);
       }
       }

    return 0;
}
コード例 #3
0
int
main(int argc, char *argv[]) {
  struct node *list;
  int i;

  /* 4 <-> 3 <-> 2 <-> 1 <-> 0 */
  for (i = 0; i < 5; i++)
    add_as_head(&list, i);

  /* 4 <-> 3 <-> 2 <-> 1 <-> 0 <-> 99 */
  add_as_tail(&list, 99);

  /* 4 <-> 3 <-> 2 <-> 1 <-> 0 */
  delete_node_by_value(&list, 99);

  /* 3 <-> 2 <-> 1 <-> 0 */
  delete_head(&list);
  
  /* 3 <-> 1 <-> 0 */
  delete_node(list->next);

  /* 3 <-> 1 */
  delete_tail(&list);
  
  disp_list(list);

  free_list(&list);

  return EXIT_SUCCESS;
}
コード例 #4
0
ファイル: headfoot.cpp プロジェクト: kalinsha08/KSFeed
void HeadFoot::set_headfoot(const char* szHead, const char* szFoot )
{
	delete_head();
	delete_foot();
    
   	copy_head(szHead, "abc");
    copy_foot(szFoot, "xyz");
}
コード例 #5
0
ファイル: head.c プロジェクト: CodeSmithyIDE/libgit2
void test_repo_head__retrieving_a_missing_head_returns_GIT_ENOTFOUND(void)
{
	git_reference *head;

	delete_head(repo);

	cl_assert_equal_i(GIT_ENOTFOUND, git_repository_head(&head, repo));
}
コード例 #6
0
ファイル: poly.cpp プロジェクト: mors741/Polynom
void delete_elem(struct item **head, item *elem)
{
    if (elem == *head)
        delete_head(head);
    else
    {
        struct item *p = find_prev(*head, elem);
        p->next = elem->next;
        free(elem);
    }

}
コード例 #7
0
ファイル: Fst2Check_lib.cpp プロジェクト: adri87/Q-A
/**
 * Returns 1 and prints an error message if a recursion is found in graph #n;
 * returns 0 otherwise.
 */
int look_for_recursion(int n,struct list_int* l,Fst2* fst2,int* graphs_matching_E,U_FILE*ferr) {
if (is_in_list(n,l)) {
   /* If we find a graph that has already been visited */
   print_reversed_list(l,n,fst2->graph_names,ferr);
   error(" recalls the graph %S\n",fst2->graph_names[n]);
   if (ferr != NULL)
      u_fprintf(ferr," recalls the graph %S\n",fst2->graph_names[n]);
   return 1;
}
l=new_list_int(n,l);
int ret=explore_state(fst2->initial_states[n],l,fst2,graphs_matching_E,ferr);
delete_head(&l);
return ret;
}
コード例 #8
0
ファイル: ishead.c プロジェクト: ANNAVARAMVENKATESH/libgit2
void test_refs_branches_ishead__can_properly_handle_missing_HEAD(void)
{
	git_repository_free(repo);

	repo = cl_git_sandbox_init("testrepo.git");

	delete_head(repo);

	cl_git_pass(git_reference_lookup(&branch, repo, "refs/heads/master"));

	cl_assert_equal_i(false, git_branch_is_head(branch));

	cl_git_sandbox_cleanup();
	repo = NULL;
}
コード例 #9
0
void *thread_pool(void *sv){
	while(1){
		pthread_mutex_lock( &conditionMutex ); 
		struct server *my_sv = (struct server*)sv;
		while(ready_queue == NULL)
			pthread_cond_wait(&Notempty,&conditionMutex); 
		int connfd  = ready_queue->key;
		
		if(counter>=buffer_max)
			pthread_cond_signal( &Notfull ); 
		ready_queue = delete_head(ready_queue); // delete it from the queue
		pthread_mutex_unlock( &conditionMutex ); 

		do_server_request(my_sv, connfd);
	}
	return NULL;
}
コード例 #10
0
struct node *delete_node(struct dl_list *list, struct node *to_die){
	if(!to_die->next){
		//data == list->tail
		return delete_tail(list);
	}
	else if(!to_die->prev){
		//data == list->head		
		return delete_head(list);
	}
	else{
		to_die->prev->next = to_die->next;
		to_die->next->prev = to_die->prev;
		--(list->size);
		to_die->next = to_die->prev = NULL;
		return to_die;
	}
}
コード例 #11
0
//delete tail if input is larger than list size
//delete the element immediately after the zth node
struct node *delete_at(struct dl_list *list, int z){
	if(is_empty(list)){
		//nothing to delete
		return NULL;
	}
	else if(z == 0){
		return delete_head(list);
	}
	else if(z >= list->size){
		return delete_tail(list);
	}
	else{
		struct node *temp = list->head;
		while(z-- > 0){
			temp = temp->next;
		}
		return delete_node(list, temp);
	}
}
コード例 #12
0
int
delete_node_by_value(struct node **list, int n) {
  struct node *tmp = NULL;

  if ((*list)->data == n) {
    return delete_head(list);
  }

  for (tmp = *list; tmp != NULL && tmp->data != n; tmp = tmp->next);

  if (tmp == NULL)
    return 0;

  if (tmp->prev != NULL)
    tmp->prev->next = tmp->next;
  if (tmp->next != NULL)
    tmp->next->prev = tmp->prev;

  return free_node(tmp);
}
コード例 #13
0
ファイル: main.c プロジェクト: bysun2013/algorithm
int main()
{
    int i;
    init_queue();
    for(i=1;i<10;i++){
        append_tail(2*i);
    }
    print_queue();

    for(i=1;i<6;i++){
        delete_head();
    }
    print_queue();

    for(i=15;i<30;i++){
        append_tail(2*i);
    }
    print_queue();

    return 0;
}
コード例 #14
0
void delete_all(struct dl_list *list, const void *key, comp eq){
	//nothing to delete
	if(is_empty(list)){
		return;
	}
	//list not empty
	struct node *cur;
	struct node *temp;
	for(cur = list->head; cur != NULL; ){
		//Key found
		if(eq(cur->data, key)){
			//cur is head
			if(!cur->prev){
				destroy_node(delete_head(list));
				cur = list->head;
			}
			//cur is tail
			else if(!cur->next){
				destroy_node(delete_tail(list));
				cur = NULL;
			}
			else{
				cur->prev->next = cur->next;
				cur->next->prev = cur->prev;
				temp = cur;
				cur = cur->next;
				destroy_node(temp);
				--(list->size);
			}
		}
		//key not found
		else{
			cur = cur->next;
		}
	}
}
コード例 #15
0
ファイル: LinkdedList.c プロジェクト: yhw920330/Algorithm
void deleteAll(List * a){
	int i= a->length;;
	while(i--){
		delete_head(a);
	}
}
コード例 #16
0
ファイル: buffer.c プロジェクト: afghanistanyn/websshproxy
/**
 * 非阻塞写,从第一个block到pos位置
 * return 发送的总数据量
 */
ssize_t write_buffer( int fd, buffer_t *pbuf ) {
	
	assert(fd >= 0);
	assert( pbuf != NULL);

	block_t		*pb = NULL;
	int			n, total, size;
	
	total = 0;
	g_errno = 1;

NONWRITE:
	if ( 0 == pbuf->size )			//结束发送
		return total;
	pb = BUFFER_HEAD(pbuf);
	if ( NULL == pb ) {
		log_message( LOG_ERROR, "head = NULL, but remain size:%d", pbuf->size );
		return total;		
	}
	if ( 0 == BLOCK_SENDATA(pb) ) {	//块没有数据发了
		delete_head( pbuf );		
		goto NONWRITE;
	}
	size = BLOCK_SENDATA(pb);
	n = send( fd, BLOCK_SENDADDR(pb), size, 0 );
	log_message( LOG_DEBUG, "send %d bytes to fd[%d]", n, fd );

	if ( n >= 0 ) {
		g_errno = 1;
		pbuf->size -= n;
		pb->pos += n;
		total += n;
		
		if ( n == size ) {			//块数据发送完,其实不应该删除,判断有没有满
			delete_head( pbuf );		
			goto NONWRITE;			//et mode
		}
	}
	else {
		switch (errno) {
#ifdef EWOULDBLOCK
		case EWOULDBLOCK:
#else
#  ifdef EAGAIN
		case EAGAIN:
#  endif
#endif
		case EINTR:
			g_errno = 1;			//没有错误,等待下一次事件
			break;

		case ENOBUFS:
		case ENOMEM:
			log_message(LOG_ERROR,  "writebuff: write() error [NOBUFS/NOMEM] \"%s\" on file descriptor %d",  strerror(errno), fd);
		default:
			log_message(LOG_ERROR, "writebuff: write() error \"%s\" on file descriptor %d", strerror(errno), fd); 
			g_errno = -1;
		}
	}

	return total;
}
コード例 #17
0
ファイル: headfoot.cpp プロジェクト: kalinsha08/KSFeed
HeadFoot::~HeadFoot()
{
	delete_head();
	delete_foot();
}
コード例 #18
0
ファイル: list.c プロジェクト: gauravcse/Codes
void init_menu_delete(AList_WS* list) {
	for (int i = 0; i < 4; ++i)
		printf("%s\n", MAIN_MENU[i]);

	printf("\ta. Delete data at Head\n");
	printf("\tb. Delete data at Tail\n");
	printf("\tc. Delete data at an Index\n");
	printf("\td. Delete first occurrence of a given data\n");
	printf("\te. Delete first occurrence of a given data\n");
	printf("\tf. Go Back\n");

	for (int i = 4; 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':
	{
		delete_head(list);
		break;
	}

	case '2':
	case 'b':
	case 'T':
	{
		delete_tail(list);
		break;
	}

	case '3':
	case 'c':
	case 'I':
	{
		printf("Please enter the index");
		size_t pos;
		scanf("%lu", pos);
		delete_data_at(list, pos);
		break;
	}

	case '4':
	case 'd':
	case 'D':
	{
		printf("Please enter the value you want to delete: ");
		double data;
		scanf("%lf", &data);
		delete_data(list, data);
		break;
	}

	case '5':
	case 'e':
	case 'A':
	{
		printf("Please enter the value you want to delete: ");
		double data;
		scanf("%lf", &data);

		do {
			delete_data(list, data);
		}while (find(list,data) != NOT_FOUND);
		break;
	}

	case '6':
	case 'f':
	case 'B':
		break;

	default:
		printf("Please enter a valid choice.\n\n");
		init_menu_insert(list);
	}
}