Navigation

    Fuze Arena Logo
    • Register
    • Login
    • Search
    • Categories
    • Recent
    • Popular
    • Users
    • Groups
    • Help
    • Discord

    Functions for Linked Lists

    Functions
    2
    2
    199
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • L
      LucasJG25 last edited by LucasJG25

      Shout out to Will for helping me out.
      Here are some functions for Linked Lists.

      NULL = createSprite()
      list = NULL
      
      function create_list(head, data)//{
        head = createSprite()
        head.data = data
        head.next = NULL
        return head
      //}
      
      function add_item(head, data)//{
          while head.next != NULL loop
            head = head.next
          repeat
      
          head.next = createSprite()
          head = head.next
          head.data = data
          head.next = NULL
        return void
      //}
      
      function print_list(head)//{
        print("[ ")
        while head != NULL loop
          print("( ", head.data, " )")
          head = head.next
        repeat
        print(" ]")
        return void
      //}
      
      function del_item(head, data)//{
        next = head.next
        while next.next != NULL loop
          if next.data == data then
            head.next = next.next
            removeSprite(next)
            break
          endif
          head = head.next
          next = next.next
        repeat
        return void
      //}
       
      function find_item(head, data)//{
        res = false
        while head != NULL loop
          if head.data == data then
            res = true
            break
          endif
          head = head.next
        repeat
        return res
      //}
      
      function free_list(head)//{
        while head != NULL loop
          temp = head
          head = head.next
          removeSprite(temp)
        repeat
        return void
      //}
      list = create_list(list, 0)
      for x = 1 to 10 loop
        add_item(list,x) //Adds 10 items to linked list
      repeat
      
      print_list(list) //displays entire linked list
      print(chr(10))
      del_item(list,5) //deletes the item containing data 5
      print_list(list) //displays updated linked list
      print(chr(10))
      print(find_item(list,5)) //checks if linked list has data 5
      
      free_list(list) //frees up the entire linked list
      update()
      sleep(4)
      

      Share code: NDPR2MND9K

      1 Reply Last reply Reply Quote 6
      • vinicity
        vinicity F last edited by

        Great! This will be super useful!

        1 Reply Last reply Reply Quote 1
        • First post
          Last post