This commit is contained in:
2024-11-02 15:52:55 -07:00
parent c01c467096
commit 322081b764

54
Q2.c Normal file
View File

@@ -0,0 +1,54 @@
#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
int main() {
return 0;
}