How to use pseudocodes in linked list?

Posted on 2003-03-11
Medium Priority
Last Modified: 2012-05-04
    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?
Question by:joely2k
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions

Expert Comment

ID: 8118665
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.

Accepted Solution

originalrobby earned 120 total points
ID: 8120738
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.


Robert Mezei

Expert Comment

ID: 9447199
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 
Post your closing recommendations!  No comment means you don't care.

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Although it can be difficult to imagine, someday your child will have a career of his or her own. He or she will likely start a family, buy a home and start having their own children. So, while being a kid is still extremely important, it’s also …
The SignAloud Glove is capable of translating American Sign Language signs into text and audio.
Simple Linear Regression
Suggested Courses

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question