# 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. ## 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. Why not try them and see?

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

3. 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. 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?

5. Thank you IMalc, I got that.