Example #1
0
File: 4.c Project: leicj/books
int main(void)
{
    Node *root = (Node *)malloc(sizeof(Node));
    Node *reversenode = NULL;
    Node tail;
    root->next = NULL;
    root->value = INT_MIN;

    insert(root, 2);
    insert(root, 9);
    insert(root, 3);
    insert(root, 0);
    insert(root, 4);
    insert(root, 6);
    insert(root, 1);
    insert(root, 3);
    print(root->next);

    del(root, 4);
    del(root, 0);
    del(root, 100);
    print(root->next);

    reversenode = sll_reverse(root->next);
    print(reversenode);

    return 0;
}
Example #2
0
int main (void) {
    Node *root;
    root = (Node *)malloc(sizeof(Node));
    create(root);
    printf("length is :%d\n", getListNodeNum(root));
    my_list(root);
    root = sll_reverse(root);
    my_list(root);
}
Example #3
0
void main(void){
	int arr[]={1,2,3,4,5,6,7,8,9};
	//int arr[]={1,2,3};
	//int arr[]={1,2};
	//int arr[]={1};
	int len=sizeof(arr)/sizeof(int);
	Node *list=create_list(arr,len);
	char *str=to_str(list,len);
	printf("%s\n",str);	
	Node *rev_list=sll_reverse(list);
	str=to_str(rev_list,len);
	printf("%s\n",str);
	free(str);
	free(list);
	free(rev_list);
}
Example #4
0
int main(void)
{
    char buffer[7] = {0};
    int count;
    int point_num = 0;
    char num_ans[126];

    struct node *phead = NULL;

    while (scanf("%s %d",buffer,&count) == 2){
        buffer[6] = '\0';
        point_num = str_to_num(buffer);
	struct node *ptemp = (struct node *)malloc(sizeof(struct node));
	strncpy(ptemp->num_str,buffer,strlen(buffer) + 1);
	ptemp->num = point_num * count;
	while (count > 1){
	    str_mul(buffer,ptemp->num_str,num_ans);
	    count--;
	}
	ptemp->next = phead;
	phead = ptemp;
    }

    if (phead->next != NULL)
        phead = sll_reverse(phead);

    struct node *p_index = phead;
    int flag;
    int sum_bit = 0;
    while (phead != NULL){
        sum_bit = strlen(phead->num_str);
	flag = 0;
        for (count = 125; count > 0; count--){
	    if ((phead->num_str[count] - 48) > 0){
		if (count < sum_bit - phead->num){
		    phead->num_str[sum_bit - phead->num] = '\0';
		    break;
		}
	        phead->num_str[count+1] = '\0';
	        break;
	    }
	}
	for (count = 0; phead->num_str[count] != '\0'; count++){
	    if ((phead->num_str[count] > 48) || (count == (sum_bit - phead->num))){
	        flag = 1;
	    }
	    if (count == sum_bit - phead->num)
	        putchar('.');
	    if (flag == 1)
	        putchar(phead->num_str[count]);
	}
	putchar('\n');

	phead = phead->next;
    }

    phead = p_index;
    while (phead != NULL){
        p_index = phead;
	phead = phead->next;
	p_index->next = NULL;
	free(p_index);
    }

    return 0;
}