-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuyerslist.c
74 lines (69 loc) · 2.07 KB
/
buyerslist.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include "template.h"
void showBuyersList(seller_buyer* buyerlisthead) {
TransNode *temp; int p=0;
while(buyerlisthead!=NULL) {
printf("\n\nBuyer ID: %d\n",buyerlisthead->id);
temp=buyerlisthead->memberhead;
p=0;
while(temp!=NULL) {
printf("Transaction %d\n",(p+1));
printf("Transaction ID: %d\n",temp->entry.transID);
printf("Seller ID: %d\n",temp->entry.sellerID);
printf("Amount of Energy: %f\n",temp->entry.amtOfEnergy);
printf("Price per KWh: %f\n",temp->entry.pricePerKWh);
printf("Date of transaction: %s\n",temp->entry.date);
printf("Time of transaction: %s\n\n",temp->entry.time);
temp=temp->next;
p++;
}
printf("\n");
buyerlisthead=buyerlisthead->next;
}
}
retstat createBuyersList(seller_buyer** buyerlisthead,TransNode* mainhead) {
retstat status_code=success;
unsigned int id;
TransNode *nptr, *temp;
seller_buyer* newnode,* temp2;
int present,redundant=0;
while(mainhead!=NULL) {
id=mainhead->entry.buyerID;
//Check for existance in the sellerlist
present=0;
temp2=*buyerlisthead;
while(temp2!=NULL && temp2->next!=NULL && !present) {
if(id==temp2->id) present=1;
else temp2=temp2->next;
}
if(temp2!=NULL && id==temp2->id) present=1;
if(present) {
redundant=0;
temp=temp2->memberhead;
id=mainhead->entry.transID;
while(temp->next!=NULL && !redundant) {
if(temp->entry.transID==id) redundant=1;
else temp=temp->next;
}
if(temp->entry.transID==id) redundant=1;
if(!redundant) {
nptr=createTransNode(&(mainhead->entry));
temp->next=nptr;
}
}
else {
newnode=(seller_buyer*)malloc(sizeof(seller_buyer));
newnode->next=NULL;
if(temp2!=NULL) temp2->next=newnode;
else *buyerlisthead=newnode;
newnode->id=id;
nptr=createTransNode(&(mainhead->entry));
newnode->memberhead=nptr;
}
mainhead=mainhead->next;
}
showBuyersList(*buyerlisthead);
return status_code;
}