当前位置: 首页>>代码示例>>C++>>正文


C++ display_list函数代码示例

本文整理汇总了C++中display_list函数的典型用法代码示例。如果您正苦于以下问题:C++ display_list函数的具体用法?C++ display_list怎么用?C++ display_list使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了display_list函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: main

int main(int argc, char* argv[])
{
printf("Let us formulate the problem statement to understand the deletion process. Given a key, delete the first occurrence of this key in linked list.\nTo delete a node from linked list, we need to do following steps.\n1) Find previous node of the node to be deleted.\n2) Changed next of previous node.\n3) Free memory for the node to be deleted.\nSince every node of linked list is dynamically allocated using malloc() in C, we need to call free() for freeing memory allocated for the node to be deleted.\n");
//struct node *head = NULL;
//head = (struct node*)malloc(sizeof(_node));
    _node *head = NULL;
    insert_element(&head,1);
    insert_element(&head,2); 
    display_list(head);
   // printf(" number of nodes = %d");
    insert_element(&head,7);
    insert_element(&head,8);
    insert_element(&head,9);
    insert_element(&head,12);
    insert_element(&head,111);
    display_list(head);
    //delete_node(&head,111);
    display_list(head);
    insert_element(&head,13);
    insert_element(&head,15);
    //head->next->next->next->next->next->next = head->next->next;
    int give_answer = detect_loop(head);
    //delete_node(&head,1);
    //display_list(head);
    //delete_node(&head,12);
    //display_list(head);
    //delete_node(&head,8);
    //display_list(head);
return 0;
}
开发者ID:vdahiya,项目名称:practice_problems,代码行数:30,代码来源:ll2.c

示例2: quick_sort

void quick_sort (int l[], int left, int right) {

	int i, pivot;

	/* do nothing if array contains fewer than two elements */
	if(left >= right)
		return;
	/* partition and move pivot element to v[0] */
	swap(l, left, (left+right)/2);
	display_list(l, SIZE);
	pivot = left;
	printf("Pivot: %d\n", l[pivot]);
	/*scan all items from pivot+1 */
	for (i=left+1; i<=right; i++)
		if (l[i] < l[left]) {
			printf("Compared for Swap: %d %d\n", l[i], l[left]);	
			swap (l, ++pivot, i);
			display_list(l, SIZE);
		}
	swap(l, left, pivot);
	display_list(l, SIZE);
	printf("Recursion Starts\n");
	quick_sort (l, left, pivot-1);
	quick_sort (l, pivot+1, right);
}
开发者ID:kushalkoolwal,项目名称:c_programs,代码行数:25,代码来源:sorting_func.c

示例3: main

/*
* Main method that runs operations - doesn't return values
* Reads in 3 lines: Operations, first numeric string, second numeric string
* Usage: reads in from stdin non-negative numeric strings to do addition or subtraction operations
*/
int main( void ){
	size_t op_size = 4; // max add or 
	size_t line_size = 80; // Temporary size
	char *op, *first, *second, *first_cpy, *second_cpy, *result;
	// Cant allocate space	
	if( !(op = calloc(op_size, sizeof(char))) || !(first = calloc(line_size, sizeof(char))) || !(second = calloc(line_size, sizeof(char)))){
		fprintf(stderr, "Error: Allocating memory\n");
		return 1;
	}	
	getline(&op, &op_size, stdin); // Gets the operator
	if((strcmp(op, "add\n") == 0) || (strcmp(op, "sub\n") == 0)){ // Not accepted string
		getline(&first, &line_size, stdin); // reads in first numeric string
		first_cpy = input(first);
		free(first); // already have copy now
		if(first_cpy == NULL){
			free(op);
			return 1;
		}
		getline(&second, &line_size, stdin); // reads in second numeric string
		second_cpy = input(second);
		free(second); // already have copy now
		if(second_cpy == NULL){
			free(op);
			free(first_cpy);
			return 1;
		}
		int result_size = (strlen(first_cpy) >= strlen(second_cpy)) ? (strlen(first_cpy)) : strlen(second_cpy); 
		if(!(result = calloc(result_size + 1, sizeof(char)))){ // 1 more in case has carry or negative
			fprintf(stderr, "Error: Creating memory\n");
			return 1;
		}
		if(strcmp(op, "add\n") == 0){ // Doing add operation
			int add_status = 0;
			if((add_status = add(first_cpy, second_cpy, result)) == 1){
				printf("1");
				display_list(result);
			}else if(add_status == 0){ display_list(result);}
		}else{ // subtraction
			int sub_status = 0;
			if((sub_status = sub(first_cpy, second_cpy, result)) == 1){
				printf("-");
				display_list(result);
			}else if(sub_status == 0){ display_list(result); }
		}
	}else{ // Invalid op operation
		fprintf(stderr, "Error: 1st line not equal to 'add' or 'sub'\n");
		free(op);
		free(first);
		free(second);
		return 1;
	}	
	free(op);
	free(first_cpy);
	free(second_cpy);
	free(result);
	return 0;
}
开发者ID:tmiles,项目名称:c_portfolio,代码行数:62,代码来源:strmath.c

示例4: remove_timer

/**
 * Remove a timer from the list of active timers.
 *
 * @param timerToRemove pointer on the timer to remove
 *
 * WARNING: timerToRemove MUST NOT be null (rem: static function )
 *
 */
static void remove_timer (T_TIMER_LIST_ELT* timerToRemove)
{
    T_TIMER_LIST_ELT* removePoint;

#ifdef __DEBUG_OS_ABSTRACTION_TIMER
    _log ("\nINFO : remove_timer - start: removing 0x%x to expire at %d (now = %d)", (uint32_t) timerToRemove, timerToRemove->desc.expiration, _GET_TICK());
    display_list();
#endif

    if ( NULL != g_CurrentTimerHead )
    {
        removePoint = g_CurrentTimerHead;
        while ( NULL != removePoint )
        {
            if ( timerToRemove == removePoint )
            {
                if ( NULL != timerToRemove->next )
                {
                    timerToRemove->next->prev = timerToRemove->prev ;
                }
                if ( NULL != timerToRemove->prev )
                {
                    timerToRemove->prev->next = timerToRemove->next ;
                }
            }
            removePoint = removePoint->next ;
        }

        if ( timerToRemove == g_CurrentTimerHead )
        {
            g_CurrentTimerHead = g_CurrentTimerHead->next;
            if  (NULL != g_CurrentTimerHead) {
                g_CurrentTimerHead->prev = NULL;
            }
        }
    }
    else
    {
#ifdef __DEBUG_OS_ABSTRACTION_TIMER
        _log ("\nERROR : remove_timer : list of active timer is empty ");
#endif
        panic (E_OS_ERR);
    }

    /* clean-up links */
    timerToRemove->prev = NULL;
    timerToRemove->next = NULL;
    timerToRemove->desc.status = E_TIMER_READY;


#ifdef __DEBUG_OS_ABSTRACTION_TIMER
    _log ("\nINFO : remove_timer - end ");
    display_list();
#endif
}
开发者ID:01org,项目名称:CODK-A-Firmware,代码行数:63,代码来源:timer.c

示例5: main

int main(void) {
 struct NODE *llist = (struct NODE*)malloc(sizeof(struct NODE)), *sentinal = (struct NODE*)malloc(sizeof(struct NODE));
 int number;
 
 for(number = 1; number < 150; number++){
  append_node(llist, number);
 }
 display_list(llist);
 sentinal->next = llist;
 delete_node(sentinal, 50);
 display_list(llist);
 return number;
}
开发者ID:GeorgeOnGit,项目名称:bar,代码行数:13,代码来源:llist.c

示例6: main

//---------main-------------------
int main(){
	char end;
	int operation;
	
	do{
		display_menu();
		scanf("%d",&operation);
		
		switch(operation){
			case 1 :
				display_list();
				break;
			case 2 :
				push();
				break;
			case 3 :
				pop();
				break;
			default :
				printf("Error : Wronge number entered.\n");
				break;
		}
		
		printf("\n\nDo you want to end program? Enter 'y' or 'n' : ");
		end=getche();
		printf("\n\n");
	}while(end!='y');
}
开发者ID:h4s33b,项目名称:os_simulations,代码行数:29,代码来源:stack.cpp

示例7: main

int main(int argc, char **argv)
{
  Node *head = NULL;
  char **filenames = init_filenames();
  char arg;
  char *listfile = "index";
  char *namefile = "filenames";

  while ((arg = getopt(argc,argv,"i:n:")) > 0){
    switch(arg){
      case 'i':
        listfile = optarg;
        break;
      case 'n':
        namefile = optarg;
        break;
      default:
	fprintf(stderr, "Bad arguments for printindex\n");
	exit(1);
    }
  }


    read_list(listfile, namefile, &head, filenames);
    display_list(head, filenames);

  return 0;
}
开发者ID:KanwarGill,项目名称:SimpleSearchEngine,代码行数:28,代码来源:printindex.c

示例8: insert_after

int insert_after(struct node *newNode)
{
	display_list();
	printf("\nEnter the no. of element after which you want to insert.\n");
	int n;
	scanf("%d",&n);
	struct node *temp;
	temp=head.next;
	int r=1;
	while(temp!=NULL)
	{
		if(r!=n)
		{
			r++;
			temp=temp->next;
			continue;
		}
		else
		{
			if(temp->next==NULL)
			{
				temp->next=newNode;
				newNode->prev=temp;
				break;
			}
			else{
				newNode->next=temp->next;
				newNode->prev=temp;
				temp->next->prev=newNode;
				temp->next=newNode;
				break;
			}
		}
	}
}
开发者ID:abhinav96,项目名称:doubly-linked-list,代码行数:35,代码来源:doublyLinkedList.c

示例9: main

int				main(int ac, char **av)
{
	char			buffer[2048];
	struct termios	t;
	char			read_char[5];
	t_l				*l;

	*read_char = 0;
	l = NULL;
	if (tgetent(buffer, getenv("TERM")) < 1)
		return (-1);
	term_no_canon(t);
	tputs(tgetstr("ti", NULL), 1, ft_int_putchar);
	tputs(tgetstr("vi", NULL), 1, ft_int_putchar);
	if ((l = (t_l *)malloc(sizeof(t_l))) == NULL)
		return (-1);
	ft_init_list(l);
	display_list(l, ac, av);
	tputs(tgetstr("ks", NULL), 1, ft_int_putchar);
	read_keys(read_char);
	tputs(tgetstr("ke", NULL), 1, ft_int_putchar);
	tputs(tgetstr("ve", NULL), 1, ft_int_putchar);
	tputs(tgetstr("te", NULL), 1, ft_int_putchar);
	term_canon(t);
	return (0);
}
开发者ID:Nquere,项目名称:select,代码行数:26,代码来源:main.c

示例10: main

/*
* Main method that runs all the iterations 
* Reads sequence of integers and displays the counts of the value occurance
* Returns 0 is no errors, 1 if run into input, or memory issues
*/
int main( void ){
	int status, count;
	while((status = scanf("%d",&count)) != EOF){
		if(status == 0){ // Initial count is a non-int
			fprintf(stderr, "Didn't read any input\n");
			return 1;
		}
		if(count < 1){
			fprintf(stderr, "Count must be positive\n");
			return 1;
		}
		int i = 0;
		struct occurance *values = NULL;			
		for(i = 0; i < count; i++){ // Assigns all the values
			int value;			
			if((status = scanf("%d", &value) == 0) || status == EOF){
				fprintf(stderr, "Invalid input or too few input\n");
				free_list(values);
				return 1;	
			}
			values = add(values, value); // adds & updates linked list	
		}
		display_list(values); // Displays occurances
		free_list(values); // free in memory
	}
	return 0;
}
开发者ID:tmiles,项目名称:c_portfolio,代码行数:32,代码来源:count.c

示例11: main

int main()
{
	int choice=0;
	while(1)
	{
		printf("\n1.Insert new element\n2.Delete an element\n3.Display linked list\n4.Reverse display\n0.Exit\n");
		scanf("%d",&choice);
		switch(choice)
		{
			case 0:return 0;
			case 1:
			{
				create_node();
				break;
			}
			case 2:
			{
				delete_node();
				break;
			}
			case 3:
			{
				display_list();
				break;
			}
			case 4:
			{
				reverse_display();
				break;
			}
			default:printf("\nWrong choice selected.Try again\n");
		}
	}
}
开发者ID:abhinav96,项目名称:doubly-linked-list,代码行数:34,代码来源:doublyLinkedList.c

示例12: ask_position

int ask_position(struct node *newNode)
{
	printf("\nThe linked list is ");
	int check=display_list();
	if(check==1)
	{
		printf("\nThe inserted element becomes the first element\n");
		head.next=newNode;
	}
	else
	{
		printf("\nEnter a choice\n1.Insert after an element\n2.Insert before an element\n");
		int choice;
		scanf("%d",&choice);
		switch(choice)
		{
			case 1:
			{
				insert_after(newNode);
				break;
			}
			case 2:
			{
				insert_before(newNode);
				break;
			}
			default:printf("\nWrong choice.New element not inserted.\n");
		}
	}
}
开发者ID:abhinav96,项目名称:doubly-linked-list,代码行数:30,代码来源:doublyLinkedList.c

示例13: control_size

int		control_size(t_elem *l)
{
	char	*termtype;
	int		lin;

	termtype = getenv("TERM");
	if (!termtype)
		ft_env_error();
	tgetent(NULL, termtype);
	tputs(tgetstr("cl", NULL), 1, int_char);
	lin = tgetnum("li");
	l->len = ft_list_len(l);
	if (l->len > lin - 1)
	{
		tputs(tgetstr("cl", NULL), 1, int_char);
		ft_putendl_red("Please Resize window");
		return (0);
	}
	else
	{
		tputs(tgetstr("cl", NULL), 1, int_char);
		display_list(l);
	}
	return (1);
}
开发者ID:ThomasSan,项目名称:ft_select,代码行数:25,代码来源:display.c

示例14: printf

node *remove_member(node *head)
{
    char ch[20];
    node *ptr=NULL,*prev=head;
    printf("\t\t\tHere you can remove existing member\n\n");
    printf("Name of all members (for reference) :-\n\n");
    display_list(head,0);
    printf("\n");
    while(ptr==NULL)
    {
        printf("Enter name of member : ");
        scanf(" %[^\n]",ch);
        ptr=find_user_node(head,ch);
        if(ptr==NULL)
            printf("User not found !! Try Again !!\n\n");
    }
    per_tot-=ptr->per;
    while(prev->next!=ptr)
        prev=prev->next;
    if(ptr==head)
        head=head->next;
    else
        prev->next=ptr->next;
    free(ptr);
    return head;
}
开发者ID:vaibhavdangayachvd,项目名称:C-Programming,代码行数:26,代码来源:Easy+Contry+by+VD.c

示例15: main

void main(){
  int m=2,n=3;
	struct node *t1=create_node(2);
	head=t1;
	t1->next=create_node(5);
	t1->next->next=create_node(7);
	t1->next->next->next=create_node(9);
  t1->next->next->next->next=create_node(11);
	t1->next->next->next->next->next=create_node(13);
	t1->next->next->next->next->next->next=create_node(15);

	display_list();

	alter_list(m,n);

	display_list();
  }
开发者ID:raunakkr,项目名称:DS_Algorithms,代码行数:17,代码来源:mnlist.c


注:本文中的display_list函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。