Click here to Skip to main content
15,077,931 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
I am supposed to count and list the mirror points in the circular doubly linked list. A particular element in the list is a mirror point if traversing the list in the clockwise direction from that element results in the same sequence of values as traversing the list from that element in the anticlockwise direction.

What I have tried:

All I can do is traverse in forward and backward direction.

 void traversal(struct Node* start)
    struct Node *temp = start;
    printf("\nTraversal in forward direction \n");
    while (temp->next != start)
        printf("%d ", temp->data);
        temp = temp->next;
    printf("%d ", temp->data);
    printf("\nTraversal in reverse direction \n");
    Node *last = start->prev;
    temp = last;
    while (temp->prev != last)
        printf("%d ", temp->data);
        temp = temp->prev;
    printf("%d ", temp->data);

any idea on how to solve the problem will be appreciated
Updated 13-Sep-21 20:33pm

While we are more than willing to help those that are stuck, that doesn't mean that we are here to do it all for you! We can't do all the work, you are either getting paid for this, or it's part of your grades and it wouldn't be at all fair for us to do it all for you.

So we need you to do the work, and we will help you when you get stuck. That doesn't mean we will give you a step by step solution you can hand in!
Start by explaining where you are at the moment, and what the next step in the process is. Then tell us what you have tried to get that next step working, and what happened when you did.

If you are having problems getting started at all, then this may help: How to Write Code to Solve a Problem, A Beginner's Guide[^]
Then think about it: how would you do it manually? If you can travese forward and backward, why can't you identify a mirror point?

Write down an example:
How would you find a mirror point in that?
You'd take the first element and look at one before and one after. Are they the same? is not, ignore it and try the second.
If they are, look at eteh ones two away, and so on.
If you get back to your original element, it's a mirror point

Give it a try: it's not complicated
CPallini 14-Sep-21 2:04am
How do I find mirror points in circular doubly linked list

As programmer, your job is to uncover algorithms solving given problems.
If you don't know an algorithm yet, have to train yourself solving the problem until you, are confident you have a correct algorithm.
Take a sheet of paper, a pencil and train to solve the problem.
Since it is circular list, write a list of numbers in circle, then see how you find mirror points. Your solving method is basically your algorithm.
Then you can start to write code.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900