You are on page 1of 2

enerati in C language o lista simplu inlantuita ordonata descrescator ce sa contina valorile naturale din

inteervalul [200,100]. Afisati lista simplu inlantuita sub forma: nr.crt valoare

ChatGPT

Sure! Here's an example of how you can generate and display a singly linked list in descending order,
containing natural numbers from the interval [200, 100]. Please note that the following code assumes you
have a basic understanding of the C programming language:

cCopy code

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

// Structure for a node in the linked list


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

// Function to create a new node


struct Node* createNode(int value) {
struct Node* newNode = (struct Node*)malloc(sizeof(struct Node));
newNode->data = value;
newNode->next = NULL;
return newNode;
}

// Function to insert a node at the beginning of the linked list


void insertNode(struct Node** head, int value) {
struct Node* newNode = createNode(value);
newNode->next = *head;
*head = newNode;
}

// Function to display the linked list


void displayList(struct Node* head) {
struct Node* temp = head;
int count = 1;

printf("nr.crt\tvaloare\n");
while (temp != NULL) {
printf("%d\t%d\n", count, temp->data);
temp = temp->next;
count++;
}
}

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

// Generate the linked list in descending order


for (

You might also like