Advertisement
pleasedontcode

"Linked List" rev_01

Nov 7th, 2024
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /********* Pleasedontcode.com **********
  2.  
  3.     Pleasedontcode thanks you for automatic code generation! Enjoy your code!
  4.  
  5.     - Terms and Conditions:
  6.     You have a non-exclusive, revocable, worldwide, royalty-free license
  7.     for personal and commercial use. Attribution is optional; modifications
  8.     are allowed, but you're responsible for code maintenance. We're not
  9.     liable for any loss or damage. For full terms,
  10.     please visit pleasedontcode.com/termsandconditions.
  11.  
  12.     - Project: "Linked List"
  13.     - Source Code NOT compiled for: Arduino Uno
  14.     - Source Code created on: 2024-11-08 04:29:34
  15.  
  16. ********* Pleasedontcode.com **********/
  17.  
  18. /****** SYSTEM REQUIREMENTS *****/
  19. /****** SYSTEM REQUIREMENT 1 *****/
  20.     /* This Arduino project focuses on integrating */
  21.     /* sensors and actuators to create an automated */
  22.     /* system, enhancing functionality through responsive */
  23.     /* programming and reliable performance. */
  24. /****** END SYSTEM REQUIREMENTS *****/
  25.  
  26. /* START CODE */
  27.  
  28. /****** DEFINITION OF LIBRARIES *****/
  29. #include <Arduino.h>  // Include Arduino library for Arduino functions
  30.  
  31. struct node {
  32.     int data;
  33.     struct node* link;
  34. };
  35.  
  36. struct node* head;
  37. struct node* current;
  38.  
  39. /****** FUNCTION PROTOTYPES *****/
  40. void setup(void);
  41. void loop(void);
  42.  
  43. void setup(void)
  44. {
  45.     // Initialize the linked list with nodes
  46.     head = (struct node*)malloc(sizeof(struct node)); // Allocate memory for head
  47.     head->data = 45;
  48.     head->link = NULL;
  49.  
  50.     current = (struct node*)malloc(sizeof(struct node)); // Allocate memory for current
  51.     current->data = 98;
  52.     current->link = NULL;
  53.  
  54.     head->link = current;
  55.  
  56.     current = (struct node*)malloc(sizeof(struct node)); // Allocate memory for another node
  57.     current->data = 3;
  58.     current->link = NULL;
  59.  
  60.     head->link->link = current;
  61.  
  62.     // The following lines are commented out because they are not compatible with Arduino
  63.     // struct node *ptr;
  64.     // ptr = head;
  65.     // current = malloc(sizeof(struct node)); // Missing closing parenthesis
  66.     // Serial.print("data want to insert="); // Use Serial for output
  67.     // while (!Serial.available()); // Wait for user input
  68.     // int x = Serial.parseInt(); // Read integer from Serial
  69.     // current->link = NULL; // Missing semicolon
  70.     // struct node*ptr, // Duplicate declaration
  71.     // ptr = head;
  72.     // while(ptr->link != NULL) // Incorrect spacing
  73.     // {
  74.     //     ptr = ptr->link;
  75.     // }
  76.     // ptr->link = current;
  77. }
  78.  
  79. void loop(void)
  80. {
  81.     // put your main code here, to run repeatedly:
  82. }
  83.  
  84. /* END CODE */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement