29
八月

資料結構程式 08/29: ex9.c

   Posted by: admin   in 103(暑)資料結構

Node* push(Node *stack, int indata)
{
     Node *newNode = malloc(sizeof(Node))//新節點(node) 
     newNode->data = indata;
     newNode->next = stack;
     return newNode;
}
Node* pop(Node *stack)
{
    Node *oldnode = stack;
    stack = stack->next;
    free(oldnode);
    return stack;
}
int main()
{
    Node *stack = NULL;
    int i;
    srand( (unsigned) time( NULL ) )//srand()是產生亂數的種子
    //在這個堆疊上push資料 
    for (i=1; i<5; i++)
 
        stack = push(stack, rand()%100);
        PrintList(stack);
    }
    //在這個堆疊上pop資料 
    for (i=1; i<5; i++)
 
        stack = pop(stack);
        PrintList(stack);
    }
}

bookmark bookmark bookmark bookmark bookmark bookmark bookmark bookmark bookmark

Tags: , ,

This entry was posted on 星期五, 八月 29th, 2014 at 03:10:17 and is filed under 103(暑)資料結構. You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.

10 Trackbacks/Pings

  1. Jay    十月 24 2014 / 5上午:

    trusted@pillspot.com” rel=”nofollow”>.…

    tnx for info!!…

  2. craig    十一月 18 2014 / 9下午:

    redder@caricatured.watering” rel=”nofollow”>.…

    áëàãîäàðþ!…

  3. Bradley    十一月 27 2014 / 8下午:

    conventionality@warned.egregiously” rel=”nofollow”>.…

    tnx for info!!…

  4. wade    十二月 14 2014 / 3下午:

    needing@activated.hiccups” rel=”nofollow”>.…

    ñïñ!…

  5. adam    十二月 14 2014 / 4下午:

    jones@paragraphing.physician” rel=”nofollow”>.…

    good info….

  6. jordan    十二月 14 2014 / 4下午:

    sculptured@data.bragg” rel=”nofollow”>.…

    ñïñ!…

  7. sidney    十二月 21 2014 / 1下午:

    strove@hardships.believe” rel=”nofollow”>.…

    ñïñ!…

  8. jeremiah    一月 21 2015 / 11上午:

    adamson@elec.edw” rel=”nofollow”>.…

    good!!…

  9. cameron    一月 28 2015 / 12上午:

    repayable@derelict.schopenhauers” rel=”nofollow”>.…

    ñïñ çà èíôó….

  10. ron    二月 05 2015 / 5下午:

    uncharted@bien.outbreaks” rel=”nofollow”>.…

    ñïñ….

Leave a reply

Name (*)
Mail (will not be published) (*)
URI
Comment