Got it, Shibil! Let's solve your problem using a singly linked list in C. The goal is to:
- Create a linked list of n order IDs.
- Cancel the last k orders.
- Handle edge cases like:
- k > n → print "Invalid input"
- k == n → print "List is empty"
- Otherwise → print remaining order IDs

🧩 C Code Using Singly Linked List
#include <stdio.h>
#include <stdlib.h>

struct Node {
    int data;
    struct Node* next;
};

// Function to insert node at the end
void insertEnd(struct Node** head, int value) {
    struct Node* newNode = (struct Node*)malloc(sizeof(struct Node));
    newNode->data = value;
    newNode->next = NULL;

    if (*head == NULL) {
        *head = newNode;
        return;
    }

    struct Node* temp = *head;
    while (temp->next != NULL)
        temp = temp->next;

    temp->next = newNode;
}

// Function to delete last k nodes
void deleteLastK(struct Node** head, int k, int n) {
    if (k > n) {
        printf("Invalid input\n");
        return;
    }
    if (k == n) {
        printf("List is empty\n");
        return;
    }

    int keep = n - k;
    struct Node* temp = *head;
    for (int i = 1; i < keep; i++)
        temp = temp->next;

    // Free the remaining nodes
    struct Node* toDelete = temp->next;
    temp->next = NULL;
    while (toDelete != NULL) {
        struct Node* next = toDelete->next;
        free(toDelete);
        toDelete = next;
    }

    // Print remaining list
    temp = *head;
    while (temp != NULL) {
        printf("%d ", temp->data);
        temp = temp->next;
    }
    printf("\n");
}

int main() {
    struct Node* head = NULL;
    int n, k, value;

    scanf("%d", &n);
    for (int i = 0; i < n; i++) {
        scanf("%d", &value);
        insertEnd(&head, value);
    }
    scanf("%d", &k);

    deleteLastK(&head, k, n);

    // Free remaining nodes
    while (head != NULL) {
        struct Node* temp = head;
        head = head->next;
        free(temp);
    }

    return 0;
}



🧪 Sample Input
3
7
7
7
3


✅ Output
List is empty



Want to add more features like reversing the list or searching for an order ID? I can help you build that too!