Linkedlist Attempt,recitating push_back function , print function,

Published

2025-09-27

Modified

2025-09-27

Attempt 1

Show the code
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

typedef struct Node{
    int info;
    struct Node *next;
}Node;

Node* push_back(Node *last, int info);
void print_list(Node *head);




int main(void){
    Node *head = NULL, *tail = NULL;
    tail = push_back(NULL,11); 
    head = tail;
    print_list(head); 
    return 0;
}

Node* push_back(Node *last, int info){
    if(last == NULL){
        Node *newNode = (Node *)malloc(sizeof(Node));
        //loaded info value
        newNode->info = info;
        //setup the next pointer to NULL
        newNode->next = NULL;
           //return the back of the list
        return newNode;
    }
}
//print function
void print_list(Node *head){
    Node *cur = head;
    while (cur!= NULL){
        printf("%d ->", cur->info);
        cur = cur->next;
    }
    printf("NULL\n");
}
    

execution result

11 ->NULL

=== Code Execution Successful ===

Show the code

<>

##Execution result