GoConqr has a new look! Let us know what you think.

Flashcards

254 notes

Sarah Hrubetz Computer Science English 35 cards

Cards in this deck (35)

  1. 1What is wrong with writing a make Empty function for sorted Lists that only has the line of code: header->next=nullptr; ?You will have a constructor calling a constructor which can lead to stack overflow.
  2. 2Why is it necessary to write a destucter for sorted list?If you don't write a destructer for sorted list, if you have 10,000 nodes but write ten things, you will have stack overflow, the pointer gets destroyed freeing nodes.
  3. 3What are three ways a destructer is called?If you create an object in heap that has a destructer and has a raw pointer pointing to it and deleting that pointer.
    If you have the object declared on a block {} and leave the block
    At the end of program execution
  4. 4What is the copy constructorIt is a constructor used to make a copy of an object, when passed by value.
  5. 5What is an actual parameter and formal parameter?An actual in the function call, formal is the parameter in the function heading.
  6. 6In what three situations is a copy constructor called?-passing an object by value
    -returning an object by value
    -assigning an object to an object being declared
  7. 7Why do we return *this when writing a copy assignment?Because we might be doing multiple assignments.
  8. 8What is the keyword this?a ptr to an object that owns the function being executed
  9. 9What is the advantage and disadvantage of using a move constructor compared to a copy constructor?It's faster to use a move constructor, but you lose the original.
  10. 10What is the difference between an lvalue and an rvalue?Lvalue is a value that's more permanent the rvalue is tempory.
  11. 11What is an important requirement for values passed as parameters to a move constructor or a move assignment?They have to be rvalues.
  12. 12What indicates this in formal parameters?&&
  13. 13What does the move function do?foo(move(bar));
    the move will make bar an rvalue, and that will use the move constructor
  14. 14What is the purpose of writing begin and end functions?Those beginning and end functions are used for unseen for loops, they return IterInfo objects so they can be seen by the unseen for loop.
  15. 15What are 3 overloaded operator functions for the IterInfo class and how do they relate to the unseen for loop?We have != makes the range based for loop stop
    * gets next element out of data structure and returns it to the for loop
    ++ used to go to the next element of the data structure
  16. 16Explain what return by reference means?You are returning the location.
  17. 17What is the purpose of returning by reference for the dereference operator of the IterInfo class?so the client can make changes in the ranged based for loop.
  18. 18What is emplacing?Moving
  19. 19Explain the strategy we use in class for expansion and contraction of vectors.Double the size of the vector when filled
    If we get down to 25% being used we cut it in half
  20. 20Why not use the following strategy for expansion and contracting vectors: when we add an element expand the vector by one when we remove an element contract the vector by one?Every time you add or take out an element you would have to create a new vector in the heap and copy and replace those elements from the old one to the new one.
  21. 21What is an advantage and disadvantage of unique_ptr compared with shared_ptr? What is a unique ptr usually used for?Unique ptr is 4 bytes, shared is 8 bytes
    cannot have 2 unique ptrs pointing to the same object.
    Used to point to arrays that are made on the heap.
  22. 22Why do we return by reference for the overloaded [] operator in slim vector?If we are returning the location it is actually a function call, return by reference can assign something to that location.
  23. 23What are 3 ways of handling the five special functions?-Write the function defention for them
    -Write the function prototype and assign default to it
    -Write the function prototype and assign delete to it
  24. 24When should we handle all 5 special functions?If you handle one, you should handle them all.
  25. 25What is the effect of assigning default to the prototype of a special function?It is what the function would normally do if you did not write special functions at all.
  26. 26Define enqueue, dequeue, and FIFO?Enqueue adds elements to the end of the queue
    Dequeue removes elements from the front
    First in first out
  27. 27In the linked list implementation of a queue, why is it important to maintain a ptr called back that points to the end of a queue?it makes it easier to add elements to the end, otherwise, you would have to cycle node by node.
  28. 28In the vector implementation of a queue, how do you know when the vector is full?-when end+1==front
    -front==0&&end==size-1
  29. 29In the vector implementation of a queue, why do the elements sometimes need to be rearranged when the vector is doubled or cut in half?When you double it move the front ptr to the end of it to avoid having a gap in the middle
    If you cut it in half, you will lose elements on the second half
  30. 30Explain how a default parameter works.void foo(int a, bool b=true)
    2 ways to call:
    foo(10); a is 10 b is true
    foo(5,false) a is 5 b is false
  31. 31Explain what an initializer list does.foo(int a, char ch)
    :x(a),y(ch)
    {
    //assigns a to x and ch to y
    }
  32. 32When is a linked list faster than a vector?Inserting an element to the middle of the linked list
    element size is greater than 128
  33. 33What is a circular linked list?The last node points to the first node.
  34. 34What is a doubly-linked list?Two pairs in each node one points to the element behind, the other to the element before.
  35. 35What is deque?A queue where you can enqueue or dequeue from either direction.

Information

Description
Computer Science Flashcards on 254 notes, created by Sarah Hrubetz on 17/11/2016.
Created by
Sarah Hrubetz
Views
0
Rating

Feedback

What is it about?

What do you think of the new look?

How do you like it?