SHARE
TWEET

מבנה נתונים שאלה 1 - מעבדה 1

Osher15151 Nov 19th, 2019 66 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4.  
  5. struct node
  6. {
  7.     int data;
  8.     struct node *next;
  9. }*stnode;
  10.  
  11.  
  12. void main()
  13. {
  14.     int i, n;
  15.     int  item;
  16.     struct node *new_node, *p, *head;
  17.     printf("Enter number of Nodes :");
  18.     scanf_s("%d ", &n);
  19.     printf("Enter Value : \n");
  20.     scanf_s("%d", &item);
  21.  
  22.     new_node = (struct node *)malloc(sizeof(new_node)); // הקצאה לצומת חדשה
  23.     new_node->data = item; // Value = Inputed Item
  24.     new_node->next = NULL; // Next = NULL
  25.  
  26.     head = new_node; // First Node = Head
  27.     p = new_node; // Pointer to the first node that inputed.
  28.  
  29.     for (i = 1; i < n; i++) // Loop to Scan Node input N times.
  30.     {
  31.         printf("Enter Next Node : \n");
  32.         scanf_s("%d ", &item);
  33.    
  34.  
  35.     new_node = (struct node *)malloc(sizeof(new_node)); // הקצאה לצומת חדשה
  36.     new_node->data = item; // Value = Inputed Item
  37.     new_node->next = NULL; // Next = NULL
  38.  
  39.     p-> next = new_node; // Linking Node A to Node B to ........
  40.     p = p-> next; // P Moves to B Node ... Waiting for Another Iteration......
  41.  
  42.     }
  43.  
  44.     p->next = head; // Points to the First Node --- > This Statement make it Circular Linked List.
  45.  
  46.  
  47.  
  48.  
  49.  
  50.  
  51.  
  52.  
  53. }
  54.  
  55.  
  56.  
  57.  
  58.  
  59.  
  60.  
  61. //void deleteListInstance(node *list, list_item x)
  62. //{
  63.     /////// Delete from the list.
  64. //}
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top