0% found this document useful (0 votes)
6 views1 page

GPT Promp Refs

Uploaded by

facesearchsel
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views1 page

GPT Promp Refs

Uploaded by

facesearchsel
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 1

# Trabalho de listas ligadas em C

#include <stdio.h>
#include <stdlib.h>

struct Node {
int data;
struct Node* next;
};

void append(struct Node** head_ref, int new_data) {


struct Node* new_node = (struct Node*)malloc(sizeof(struct Node));
struct Node* last = *head_ref;
new_node->data = new_data;
new_node->next = NULL;

if (*head_ref == NULL) {
*head_ref = new_node;
return;
}

while (last->next != NULL)


last = last->next;

last->next = new_node;
}

void printList(struct Node* node) {


while (node != NULL) {
printf("%d -> ", node->data);
node = node->next;
}
printf("NULL\n");
}

int main() {
struct Node* head = NULL;

append(&head, 1);
append(&head, 2);
append(&head, 3);

printList(head);

return 0;
}

You might also like