Advertisement
STANAANDREY

multilist

Jan 14th, 2024 (edited)
430
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.26 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <stdbool.h>
  4.  
  5. typedef struct {
  6.     int code;
  7. } Prod;
  8.  
  9. #define LEN_MAX 100
  10. typedef struct {
  11.     Prod prods[LEN_MAX];
  12.     int len;
  13. } ProdList;
  14.  
  15. #define NAME_MAX 25
  16. typedef struct {
  17.     char name[NAME_MAX];
  18.     ProdList plist;
  19. } Store;
  20.  
  21. typedef struct StoreNode {
  22.     Store store;
  23.     struct StoreNode* nxt;
  24. } StoreNode;
  25.  
  26. typedef struct {
  27.     StoreNode* first;
  28.     StoreNode* last;
  29. } StoreList;
  30.  
  31. StoreNode* newStoreNode(const Store *const store, StoreNode* nxt) {
  32.     StoreNode* node = (StoreNode*)malloc(sizeof(StoreNode));
  33.     if (node == NULL) {
  34.         perror("");
  35.         exit(EXIT_FAILURE);
  36.     }
  37.     node->store = *store;
  38.     node->nxt = nxt;
  39.     return node;
  40. }
  41.  
  42. void initStoreList(StoreList* storeList) {
  43.     storeList->first = storeList->last = NULL;
  44. }
  45.  
  46. void deleteProductByCode2(ProdList* plist, int code) {
  47.     for (int i = 0; i < plist->len; i++) {
  48.         if (plist->prods[i].code == code) {
  49.             for (int j = i + 1; j < plist->len; j++) {
  50.                 plist->prods[j - 1] = plist->prods[j];
  51.             }
  52.             i--;
  53.             plist->len--;
  54.         }
  55.     }
  56. }
  57.  
  58. void deleteProductByCode(StoreList* storeList, int code) {
  59.     for (StoreNode* node = storeList->first; node; node = node->nxt) {
  60.         deleteProductByCode2(&node->store.plist, code);
  61.     }
  62. }
  63.  
  64.  
  65. int main(void) {
  66.  
  67.     return 0;
  68. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement