[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2370
  • Last Modified:

How to use pseudocodes in linked list?

    node *pointsHead, *pointsTail, *temp;

     pointsHead = new node;
     strcpy(pointsHead->playerName, "HUMAN");
     pointsHead->playerPoint = 0;
     pointsHead->next = NULL;

     pointsTail = new node;
     strcpy(pointsTail->playerName, "COMPUTER");
     pointsTail->playerPoint = 0;
     pointsTail->next = pointsHead;

     pointsHead = pointsTail;
     pointsTail = pointsHead->next;




How can I simply tell the above algorithm in Pseudocodes?
Thanks....
0
joely2k
Asked:
joely2k
1 Solution
 
madfaceCommented:
not sure what you mean but try this

pointsHead <-- allocate node
strcpy(pointsHead.playerName, "HUMAN")
pointsHead.playerPoint <-- 0
pointsHead.next <-- nothing

pointsTail <-- allocate node
strcpy(pointsHead.playerName, "COMPUTER")
pointsTail.playerPoint <-- 0
pointsTail.next <-- pointsHead

pointsHead <-- pointsTail
pointsTail <-- pointsHead.next

as you my know different software dev firms may write there pseudocode different. There is no set standard for it.
Oh ya you should really write psuedocode first then write your code, it will be good practice for you when you get to the REAL job.
0
 
originalrobbyCommented:
There are several ways to do it in pseudocode, different formal templates, here is a formal one used everywhere:

Algorithm insert_at_head()
Pre: none
Post: inserts node at head
Returns: 1 for insertion or 0 for failed insertion
 - allocate memory for node
 - store data in node
 - set node as head by pointing to the head
End Algorithm insert_at_head()

Algorithm insert_at_middle()
Pre: list must not be empty
Post: inserts a node sorted somewhere in the list
Returns: 1 for insertion or 0 for failed insertion
 - allocate memory for node
 - store data in node
 - make previous pointer point to this new pointer and this new pointer to next to connect chain
End Algorithm insert_at_middle()

Algorithm insert_at_end()
Pre: list must not be empty and next available pointer is null/tail(end of list)
Post: returns 1 for insertion or 0 for failed insertion and creates a circular list
 - allocate memory for node
 - store data in node
 - connect the the tail node to the head node
End Algorithm insert_at_end()


There that is the pseudocode for you code, I am assuming you are inserting at head, middle and end and creating a circular list with your last statement pointsTail->pointsHead.next.

Although your code is not functional, this is the pseudocode for that code.

Regards,

Robert Mezei
Programmer/Analyst
0
 
CleanupPingCommented:
joely2k:
This old question needs to be finalized -- accept an answer, split points, or get a refund.  For information on your options, please click here-> http:/help/closing.jsp#1 
EXPERTS:
Post your closing recommendations!  No comment means you don't care.
0

Featured Post

The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now