Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void AddNewItem(PItem* head, PItem* tail, int n, int a, float b)
- {
- PItem curr, prev = NULL, temp = (PItem)malloc(sizeof(struct Item));
- int pos = 1;
- if (temp == NULL)
- {
- DeleteList(head);
- Error_Msg("Memmory!");
- }
- temp->num = a;
- temp->price = b;
- curr = *head;
- if (head != NULL)
- {
- while (curr->next != NULL && pos != n)
- {
- prev = curr;
- curr = curr->next;
- pos++;
- }
- if (pos == 1) // Set NewItem as head
- {
- temp->next = *head;
- *head = temp;
- }
- else if (curr->next == NULL && n == pos + 1) // Set NewItem as tail
- {
- (*tail)->next = *tail;
- *tail = temp;
- }
- else if (n > pos + 1)
- return; //Position not valid
- else
- {
- prev->next = temp;
- temp->next = curr;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement