Ejemplo n.º 1
0
int main() { 
    LinkList l;
	l = init(5);
	printLink(l);
	insertEle(l, 6, 10);
	printLink(l);
	delNode(l, 2);
	printLink(l);
	updateNode(l, 5, 22);
	printLink(l);
	return 0;
}
Ejemplo n.º 2
0
int
main (void)
{
  link_t *h;
  int i;
  char *p;

  h = initLink ();

  for (i = 0; i < 1024 * 2; i++)
    {

      p = malloc (128);
      enqueueLink (h, p);
      printf ("%p enqueued\n", p);
    }

  printLink (h);

  while ((p = dequeueLink (h)))
    {
      printf ("%p dequeued\n", p);
      free (p);
    }

  finLink (h);

  return 0;
}
Ejemplo n.º 3
0
Archivo: ds.c Proyecto: dubenju/javay
int main(void) {
	puts("!!!Hello World!!!"); /* prints !!!Hello World!!! */

	LinkList l;
	l = init(5);
	printLink(l);
	insertEle(l, 6, 10);
	printLink(l);
	delNode(l, 2);
	printLink(l);
	updateNode(l, 6, 22);
	printLink(l);
	printf("this is a test for list by c./n");

	return EXIT_SUCCESS;
}
Ejemplo n.º 4
0
int main(int argc, char **argv)
{
	int  a = 1;	
	LNode *head;
	head = createLinkList(head);
	head->data++;
	printLink(head);
	return 0;
}
Ejemplo n.º 5
0
int main()
{
    int value;
    List li = NULL;
    li = push(li, 1);
    li = push(li, 2);
    li = push(li, 3);
    int ret = printLink(li);
    li = pop(li, &value);
    printf("pop value %d\n", value);
    li = pop(li, &value);
    printf("pop value %d\n", value);
    li = pop(li, &value);
    printf("pop value %d\n", value);

    return ret;
}
Ejemplo n.º 6
0
int main()
{


    clock_t start, end;
    long long i, j = 0, k;
    long long digit[2][2] = { 0 };
    char op, string_temp[9];
    char top1, top2;
    char mystring[9], mystring_temp[9];
    //	FILE *ft;
    LinkList L1, L2, L, L_temp, L1_temp, L3_adj;



    InitList(&L1);
    InitList(&L2);
    InitList(&L);
    int flags = 1;
    long long nu1, nu2;
    long long ii = 0, cnt_n = 2;
    int flags_line = 1;


    for (ii = 0; ii < 2; ii++)
    {
        mystring[ii] = getchar();
    }
    if (mystring[1] != '\n')
    {
        printf("op INput ERROR!\n");
        return 0;
    }
    op = mystring[0];
    if (op != '+' && op != '-' && op != '*' && op != '/')
    {
        printf("op INput ERROR!\n");
        return 0;
    }

    while (cnt_n)
    {
        for (ii = 0; ii < 8; ii++)
        {
            mystring[ii] = getchar();
            if (mystring[ii] == '\n')
            {
                cnt_n = cnt_n - 1;
                mystring[ii] = '\0';
                break;
            }
            else if (mystring[ii]<48 || mystring[ii] >57)
            {
                printf("opNumber INput ERROR!\n");
                return 0;
            }
        }
        mystring[ii] = '\0';
        if (ii == 8)
        {
            digit[2 - cnt_n][0] = digit[2 - cnt_n][0] + 1;
            if (cnt_n == 2)
                L1 = CreateListHead(L1, mystring, 0, 0);
            else
                L2 = CreateListHead(L2, mystring, 0, 0);
        }
        else
        {
            digit[2 - cnt_n - 1][1] = ii;
            if (digit[2 - cnt_n - 1][1] + digit[2 - cnt_n - 1][0] * 8 == 0)
            {
                printf("opNumber INput ERROR!\n");
                return 0;
            }

            if (ii)
            {
                if (cnt_n == 1)
                    L1 = CreateListHead(L1, mystring, 0, 0);
                else
                    L2 = CreateListHead(L2, mystring, 0, 0);
            }
        }
        //		mystring[0]='\0';
    }






    /*read from txt to test my input,so save it
    ft = fopen("C:\\Users\\v-xiafe\\Desktop\\ASE\\project (1)\\ConsoleApplication3\\Release\\test.txt", "r");
    if (ft == NULL)
    {
    printf("File Name Error.\n");
    return 0;
    }
    InitList(&L1);
    InitList(&L2);
    InitList(&L);
    int flags = 1;
    long long nu1, nu2;
    while (!digit[1][1])
    {
    fgets(mystring, 9, ft);
    if (strstr(mystring, "+") == NULL && strstr(mystring, "-") == NULL && strstr(mystring, "*") == NULL && strstr(mystring, "/") == NULL)
    {
    while (mystring != NULL)
    {
    //			puts(mystring);
    if (strstr(mystring, "\n") == NULL && strlen(mystring) == 9 - 1)
    {
    //	strcpy(string_temp, mystring);
    if (flags == 1)
    {
    L1 = CreateListHead(L1, mystring, 0, 0);
    digit[0][0] = digit[0][0] + 1;
    }
    else
    {
    L2 = CreateListHead(L2, mystring, 0, 0);
    digit[1][0] = digit[1][0] + 1;
    }
    }
    else
    {
    if (flags == 1)
    {
    if (strlen(mystring) == 1)
    digit[0][1] = 0;
    else
    {
    L1 = CreateListHead(L1, mystring, 0, 0);
    digit[0][1] = strlen(mystring) - 1;
    }
    }
    flags = 2;
    }
    if (feof(ft))
    break;
    else {
    fgets(mystring, 9, ft);
    if (feof(ft))
    {
    digit[1][1] = strlen(mystring);
    if (digit[1][1] == 8)
    digit[1][1] = 0;
    else
    {
    L2 = CreateListHead(L2, mystring, 0, 0);
    }
    break;
    }
    }
    }
    if (feof(ft))
    break;
    }
    else
    {
    op = mystring[0];
    //	putchar(op);
    putchar('\n');
    }
    }
    fclose(ft);
    */

    L1 = AlignList(L1, digit[0][1]);
    L2 = AlignList(L2, digit[1][1]);

    Node *p, *q, *r;
    p = L1->next;
    q = L2->next;
    if (8 * digit[0][0] + digit[0][1] == 1)
    {
        if (p->num == 0)
        {
            printf("opNumber1 INput ERROR!\n");
            return 0;
        }
    }
    if (8 * digit[1][0] + digit[1][1] == 1)
    {
        if (q->num == 0)
        {
            printf("opNumber2 INput ERROR!\n");
            return 0;
        }
    }



    if (op == '/')
    {
        //	InitList(&L1_temp);
        //	InitList(&L2_temp);
        //	Node *p, *q, *p0;
        p = L1->next;
        q = L2->next;
        nu1 = p->num;
        if (p->next)
        {
            while (p->next)
            {
                nu1 = p->num;
                p = p->next;
            }
            nu1 = 100000000 * p->num + nu1;
        }
        while (q)
        {
            nu2 = q->num;
            q = q->next;
        }
    }
    //	op = '*';
    //	Node *p,*r;
    LinkList L_re;
    InitList(&L_re);
    switch (op)
    {
    case '+':
        L_temp = add(L1, L2, L);
        printLink(L_temp);
        break;
    case '-':
        L_temp = sub(L2, L1, L);
        printLink(L_temp);
        break;
    case '*':
        start = clock();
        L_temp = mul(L1, L2, L);
        end = clock();
        p = L_temp->next;
        while (p)
        {
            r = p;
            L_re = CreateListHead(L_re, "00", p->num, 0);
            p = p->next;
            free(r);

        }
        printLink(L_re);
        printf("%d s\n", (end - start) / CLOCKS_PER_SEC);
        break;
    case '/':
    {
        long long n, cn_temp;
        //		Node *p,*q;
        LinkList p0, L_subrev, L1_temp1, L3, L3_temp, L_zc;
        InitList(&L_subrev);
        InitList(&L3);
        InitList(&L3_temp);
        InitList(&L_zc);
        L1_temp1 = L1;
        //	n = digit[0][0] * 4 + digit[0][1] - digit[1][0] * 4 - digit[1][1];
        //	int record[n][2];
        //	start = clock();
        while (1)
        {
            n = digit[0][0] * 8 + digit[0][1] - digit[1][0] * 8 - digit[1][1];
            //	printf("%dwei\n", digit[0][0] * 4 + digit[0][1]);
            digit[0][0] = 0;
            digit[0][1] = 0;
            if (n<0)
            {
                //	printLink(L3);
                //	printLink(L1_temp1);
                break;
            }
            else
            {
                k = nu1 / (nu2 + 1);
                cn_temp = pow(10, getdigit(nu1) - getdigit(nu2));
                //		printf("%d",cn_temp);
                if (nu1 / cn_temp > nu2)
                    n = n + 1;
                else
                {
                    if (n == 0)
                    {
                        //			printLink(L3);
                        //			printLink(L1_temp1);
                        break;
                    }
                }
                if (getdigit(k) > n)
                    k = k / pow(10, getdigit(k) - n);
                L_temp = getL_temp(k, n, L1_temp1, L2, &L3);
                //		printLink(L_temp);
                p = L_temp->next;
                q = L3->next;
                digit[0][1] = getdigit(p->num);
                Destory(L_subrev);
                Destory(L3_temp);
                nu1 = 0;
                while (p->next)
                {
                    L_subrev = CreateListHead(L_subrev, "00", p->num, 0);
                    //	nu1 = p->num;
                    digit[0][0] = digit[0][0] + 1;
                    p = p->next;
                }
                L_subrev = CreateListHead(L_subrev, "00", p->num, 0);
                while (q)
                {
                    L3_temp = CreateListHead(L3_temp, "00", q->num, 0);
                    q = q->next;
                }
                L3 = L3_temp;
                p = L_temp->next;
                nu1 = p->num;
                if (p->next)
                {
                    p = p->next;
                    nu1 = 100000000 * nu1 + p->num;
                }

                //		Destory(L1_temp1);
                //		Destory(L1_temp);
                L1_temp1 = L_subrev;

            }
            //	Destory(L_subrev);
        }
        //		end = clock();
        L_zc = sub(L1_temp1, L2, L_zc);
        p = L_zc->next;
        if (p->num == 0 && p->next == NULL)
        {
            p->num = 1;
            InitList(&L3_adj);
            L3_adj = add(L3, L_zc, L3_adj);
            printLink(L3_adj);
            printf("0\n");
        }
        else
        {
            p = L3->next;
            while (p)
            {
                r = p;
                L_re = CreateListHead(L_re, "00", p->num, 0);
                p = p->next;
                free(r);

            }
            printLink(L_re);
            Destory(L_re);
            p = L1_temp1->next;
            while (p)
            {
                r = p;
                L_re = CreateListHead(L_re, "00", p->num, 0);
                p = p->next;
                free(r);

            }
            printLink(L_re);
        }
        //		printf("%d s", (end - start) / CLOCKS_PER_SEC);
    }
    }
    return 0;
}
Ejemplo n.º 7
0
int main(int argc, const char * argv[])

{
    
    
    
    
    
    int a1[]={13,0,5,8,1,7,21,50,9,2};
    
    
    
    int a[num];
    
    //        int count=0;
    
    
    
    
    
    for (int i=0; i<num-1; i++) {
        
        for (int j=0; j<num-i-1; j++) {
            
            if (a[j]>a[j+1])
                
            {
                
                int tmp=a[j];
                
                a[j]=a[j+1];
                
                a[j+1]=tmp;
                
            }
            
        }
        
    }
    
    
    
    
    
    
    
    
    
    printf("The result of factorial caculation is:%d\n",factorialCaculation(6));
    
    
    
    printf("\nThe Origonal is:\n");
    
    printArray(a1, 10);
    
    
    
    printf("The sorted Array:\n");
    
    bubble(a1, 10);
    
    printArray(a1, 10);
    
    
    
    LinkList l;
    
    l = init(5);
    
    printf("\nThe Original list:\n");
    
    printLink(l);
    
    insertEle(l, 6, 10);
    
    printf("Inserted at end:\n");
    
    printLink(l);
    
    
    
    insertEle(l, 1, 0);
    
    printf("Inserted at start:\n");
    
    printLink(l);
    
    
    
    insertEle(l, 4, 2);
    
    printf("Inserted at middle:\n");
    
    printLink(l);
    
    
    
    delNode(l, 2);
    
    printf("The second num deleted:\n");
    
    printLink(l);
    
    
    
    
    
    
    
    
    
    return 0;
    
}