Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- DList::DList()
- {
- item_list = NULL;
- item_amounts = NULL;
- num_items = 0;
- }
- DList::DList(string item, int amount)
- {
- //Check to see if Lists are empty
- if (num_items < 0)
- {
- item_list = new item_list[num_items+1];
- item_amounts = new item_amounts[num_items+1];
- item_list[num_items] = item;
- item_amounts[num_items] = amount;
- }
- //if list is not empty
- else
- {
- //Create 2 temporary arrays to store previous values
- string *tempa = new tempa[num_items+1];
- int *tempb = new tempb[num_items+1];
- /*Cycle through existing arrays to copy values and leave
- one empty cell at the end of each temp array*/
- for (int i =0; i < num_items; i++)
- {
- tempa[i] = item_list[i];
- tempb[i] = item_amounts[i];
- }
- //Assign given values to last cell in temp arrays
- tempa[num_items+1] = item;
- tempb[num_items+1] = amount;
- //Deletes old arrays to create bigger ones
- delete[] item_list;
- delete[] item_amounts;
- //Create new 1-cell-larger arrays
- item_list = new item_list[num_items+1];
- item_amounts = new item_amounts[num_items+1];
- //Copy temp values to new larger arrays
- for (int i =0; i < num_items+1; i++)
- {
- item_list[i] = tempa[i];
- item_amounts[i] = tempb[i];
- }
- //Deletes temporary arrays
- delete[] tempa;
- delete[] tempb;
- //Sets Number of items to +1
- num_items++;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement