64 lines
1.1 KiB
C
64 lines
1.1 KiB
C
#include <stdio.h>
|
|
#include <string.h>
|
|
#include <stdlib.h>
|
|
|
|
typedef struct Product {
|
|
int id;
|
|
char name[30];
|
|
int quantity;
|
|
|
|
struct Product *next;
|
|
struct Product *prev;
|
|
} Product;
|
|
|
|
Product *create_product(int id, char *name, int quantity) {
|
|
Product *newProduct = (Product *)malloc(sizeof(Product));
|
|
newProduct->id=id;
|
|
strcpy(newProduct->name, name);
|
|
newProduct->quantity=quantity;
|
|
|
|
newProduct->next = NULL;
|
|
newProduct->prev = NULL;
|
|
|
|
return newProduct;
|
|
}
|
|
|
|
Product* insert_product(Product *head, int id, char *name, int quantity) {
|
|
Product *new_product = create_product(id, name, quantity);
|
|
if(new_product == NULL) {
|
|
printf("Failed to create product\n");
|
|
return new_product;
|
|
}
|
|
|
|
if(head == NULL) {
|
|
return new_product;
|
|
}
|
|
|
|
Product *temp = head;
|
|
while(temp->next != NULL) {
|
|
temp = temp->next;
|
|
}
|
|
|
|
temp->next = new_product;
|
|
return head;
|
|
}
|
|
|
|
void print_products(Product *head) {
|
|
Product *temp = head;
|
|
while(temp != NULL) {
|
|
printf("Product id: %d\n", temp->id);
|
|
printf("Name: %s\n", temp->name);
|
|
printf("Quantity: %d\n\n", temp->quantity);
|
|
temp = temp->next;
|
|
}
|
|
printf("\n");
|
|
}
|
|
|
|
int main() {
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
}
|