Code Snippets 4 U

Iterative Method

#include < stdio.h >
  int main() {
    enum xx {
      x,
      y = 5,
      z
    };
    enum xx ff = y;

    union x {
      int a;
      char x[20];
    };
    union x f;
    f.a = 5;

    printf("%d", ff);

  }

#include < stdio.h > #include < stdlib.h >
  struct node {
    int x;
    struct node * next;
  };
int main() {
  struct node * node1 = (struct node * ) malloc(sizeof(struct node));
  struct node * node2 = (struct node * ) malloc(sizeof(struct node));
  struct node * node3 = (struct node * ) malloc(sizeof(struct node));
  struct node * node4 = (struct node * ) malloc(sizeof(struct node));
  struct node * node5 = (struct node * ) malloc(sizeof(struct node));

  node1 - > x = 5;
  node1 - > next = node2;
  node2 - > x = 6;
  node2 - > next = node3;
  node3 - > x = 7;
  node3 - > next = node4;
  node4 - > x = 8;
  node4 - > next = node5;
  node5 - > x = 9;
  node5 - > next = NULL;
  struct node * t = node1;
  while (t != NULL) {
    printf("%d,", t - > x);
    t = t - > next;
  }
  struct node * ptr1 = node1;
  struct node * ptr2 = node1 - > next;
  while (ptr2 != NULL) {
    struct node * temp = ptr2 - > next;
    ptr2 - > next = ptr1;

    ptr1 = ptr2;
    ptr2 = temp;
  }
  node1 - > next = NULL;

  t = node5;
  while (t != NULL) {
    printf("%d,", t - > x);
    t = t - > next;
  }
}

Leave a Reply

Your email address will not be published. Required fields are marked *

ninety two − = 84