title: Printing Reversed linked list iteratively
body: <p>I am currently writing a program that has a function that prints a linked list in reverse.</p>
  
  <p>I need to print the reverse of what this code prints using the iterative approach. </p>
  
  <p>EDIT: It is a single linked list.</p>
  
  <p>Thanks in advance.</p>
  
  <pre><code>void print_backward_iteration(NODE *ptr) {
      NODE *last, *current;
  
      last = NULL;
  
      printf("\n");
  
      while (ptr != last) {
          current = ptr;
  
          while (current -&gt; next != last) {
              current= current -&gt; next;
          }
  
          printf("%d  ", current -&gt; data);
          last = current;
      }
  
      printf("\n");
  
  }
  </code></pre>
  
  <p>Here is my complete code:</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  
  /* declaration of structure */
  typedef struct node {
      int data;
      struct node *next;
  } NODE;
  
  /* declaration of functions */
  NODE* insert_node(NODE *ptr, NODE *new);
  NODE* find_node(NODE *ptr, int n);
  NODE* delete_node(NODE *ptr, int n, int *success_flag_ptr);
  void print_backward_iteration(NODE *ptr);
  void print_backward_recursion(NODE *ptr);
  
  int main(int argc, char *argv[]) {
      int choice, x, flag_success;
      NODE *ptr, *new, *result;
  
      ptr = NULL;
  
      do {
          printf("\n1.\tInsert Integer into linked list\n");
          printf("2.\tFind integer in linked list\n");
          printf("3.\tDelete integer from linked list\n");
          printf("4.\tPrint out integers backward using the iterative strategy\n");
          printf("5.\tPrint out integers backward using the recursive strategy\n");
          printf("6.\tQuit\n");
          printf("\nEnter 1,2,3,4,5, or 6: ");
          scanf("%d", &amp;choice);
  
          switch(choice) {
          case 1:
              printf("\nPlease enter an integer: ");
              scanf("%d", &amp;x);
              new = (NODE *)malloc(sizeof(NODE));
              new-&gt;data = x;
              ptr = insert_node(ptr, new);
              printf("\nNode Inserted with value of %d.\n", ptr-&gt;data);
              break;
  
          case 2:
              printf("\nPlease enter an integer: ");
              scanf("%d", &amp;x);
              result = find_node(ptr, x);
  
              if (result == NULL) {
                  printf("\nValue could not be found.\n");
              } else {
                  printf("\nValue %d was found.\n", x);
              }
              break;
  
          case 3:
              printf("\nPlease enter an integer: ");
              scanf("%d", &amp;x);
              ptr = delete_node(ptr, x, &amp;flag_success);
  
              if (result == NULL) {
                  printf("\nValue could not be found.\n");
              } else {
                  printf("\nValue %d was deleted.\n", x);
              }
              break;
  
          case 4:
              print_backward_iteration(ptr);
              break;
  
          case 5:
              printf("\n");
              print_backward_recursion(ptr);
              printf("\n");
              break;
  
          case 6:
              printf("\nThank you for using this program.\n");
              break;
  
          default:
              printf("\nInvalid Choice. Please try again.\n");
              break;
          }
      }
      while (choice != 6);
  
      printf("\n*** End of Program ***\n");
      return 0;
  }
  
  /* definition of function insert_node */
  NODE* insert_node(NODE *ptr, NODE *new) {
      new -&gt; next = ptr;
      return new;
  }
  
  /* definition of function find_node */
  NODE* find_node(NODE *ptr, int n) {
      while (ptr != NULL) {
          if (ptr-&gt;data == n) {
              return ptr;
          } else {
              ptr = ptr-&gt;next;
          }
      }
  
      return NULL;
  }
  
  /* definition of function delete_node */
  NODE* delete_node(NODE *ptr, int n, int *success_flag_ptr) {
      NODE *temp = NULL;
  
      if (ptr == NULL) {
          *success_flag_ptr = 0;
          return NULL;
      }
  
      if (ptr -&gt; data == n) {     
          temp = ptr-&gt;next;  
          free(ptr);         
          *success_flag_ptr = 1;
          return temp;
      } else
          ptr-&gt;next = delete_node(ptr-&gt;next,n,success_flag_ptr); 
  
      return ptr;
  }
  
  /* definition of function print_backward_iteration */
  void print_backward_iteration(NODE *ptr) {
      NODE *last, *current;
  
      last = NULL;
  
      printf("\n");
  
      while (ptr != last) {
          current = ptr;
  
          while (current != last) {
              current =  current -&gt; next;
          }
  
          printf("%d  ", current -&gt; data);
          last = current -&gt; next;
      }
  
      printf("\n");
  }
  
  /* definition of function print_backward_recursion */
  void print_backward_recursion(NODE *ptr) {
      NODE *last, *current;
  
      last = NULL;
  
      while (ptr != last) {
          current = ptr;
          printf("%d  ", current -&gt; data);
          print_backward_recursion(current -&gt; next);
          last = current;
      }
  }
  </code></pre>