algorithms

This is a discussion on algorithms within the C Programming forums, part of the General Programming Boards category; Hi, can anyone please take a look at these algorithms. Are they correct? Are they going to work? Thank you ...

  1. #1
    Registered User
    Join Date
    Oct 2008
    Posts
    92

    algorithms

    Hi, can anyone please take a look at these algorithms. Are they correct? Are they going to work?

    Thank you

    Algorithm for the linked list implementation of the following for simple lists.

    * ClearList
    fanction takes ponter of the beginning of the list (Node *list)

    while( list != NULL )

    go through the list by making pointer point to the next node and delete nodes
    one by one with free( );


    * ListEmpty
    True if no more items can be dequeued and there is no front item.

    Boolean function takes a pointer to the list and returns true if empty
    and false if not
    if (list==0) function returns true
    if not then fanction returns false


    * ListFull
    True if no more items can be enqueued.
    Boolean fanction takes a pointer to the list and returns true if full
    and false if not
    if(list!=0) function returns true
    otherwise fanction returns false

    * ListSize
    Function takes pointer of the beginning og the list and
    returns the number of nodes in the list.
    Declare and initialize integer count=0.
    while(list!=NULL)
    go throught the list and count nodes. / count++;
    return count.


    Algorithm for the array implementation of the following for simple lists.

    * ClearList
    Function takes pointer to the list.
    Check if list is empty, if empty despaly the message.
    Use finite loop (where i initialized to end of the list, go down through
    the list in the array untill
    i not equal -1)
    list[i-1].entry=list[i].entry;
    list->count--;


    * ListEmpty
    True if no more items can be removed .
    Boolean Function takes a pointer to the list.
    if list->count==-1 then function returns 0; else returns true.




    * ListFull
    True if no more items can be added.
    Boolean fanction takes a pointer to the list.
    if list->count=(MAXSIZE-1) then function returns true, othervise
    returns fauls.



    * ListSize
    Takes pointer to the beginning of the list.
    Returns number of entries in the list.
    Integer count declared and initialized to 0.
    using finit loop traverse through the list untill not equal (MAXSIZE-1)
    and count nodes.
    return count;

    Agorithms to append and serve nodes for this structure.

    appened: The new node will be placed just after the tail node
    (between the tail and the first node)
    Allocate a space for the new node
    Assign data to new node pNew->data=data; pNew->data=pNew;
    if tail is equal NULL, new node becomes tail ,
    otherwise make pNew->next and pTail-> point to the same
    location. Make tail next point to new node. New node becomes tail.

    serve: The last node will be deleted from the list
    Allocate space for temp node.
    Assigned tail->next to temp;
    make tail next and temp next pointer to point to the allocated space.
    delete temp using free();

  2. #2
    Woof, woof! zacs7's Avatar
    Join Date
    Mar 2007
    Location
    Australia
    Posts
    3,459
    Why not try them and see?

    Your post is a bizarre request, smells like homework to me.

  3. #3
    Registered User
    Join Date
    Oct 2008
    Posts
    92
    Yes it is a homework, I didn't do coding, just wrote an algorithms.
    You are right I have to try them myself, thank you.

  4. #4
    Algorithm Dissector iMalc's Avatar
    Join Date
    Dec 2005
    Location
    New Zealand
    Posts
    6,308
    Your linked-list algorithm descriptions look okay, but every function under your array implementation is either clearly going to suffer from off-by-one errors, or is doing something that doesn't make sense.
    E.g. Why does ListSize have a loop, when some of the other functions indicate that a count is stored with the data? Why would ClearList need to touch any of the items?
    My homepage
    Advice: Take only as directed - If symptoms persist, please see your debugger

    Linus Torvalds: "But it clearly is the only right way. The fact that everybody else does it some other way only means that they are wrong"

  5. #5
    Registered User
    Join Date
    Oct 2008
    Posts
    92
    Thank you IMalc, I got that.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Sorting algorithms, worst-case input
    By Leftos in forum C++ Programming
    Replies: 17
    Last Post: 06-15-2009, 01:33 PM
  2. page replacement algorithms?
    By Extrovert in forum C++ Programming
    Replies: 1
    Last Post: 08-19-2005, 12:53 AM
  3. sort algorithms mix
    By Micko in forum C++ Programming
    Replies: 3
    Last Post: 03-08-2004, 07:36 AM
  4. relative strength of encryption algorithms (blowfish, des, rinjdael...)
    By duck-billed platypus in forum A Brief History of Cprogramming.com
    Replies: 3
    Last Post: 12-30-2001, 03:20 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21