Docsity
Docsity

Prepare for your exams
Prepare for your exams

Study with the several resources on Docsity


Earn points to download
Earn points to download

Earn points by helping other students or get them with a premium plan


Guidelines and tips
Guidelines and tips

C++ Programming Concepts: Pointers, Memory Allocation, and Data Structures, Quizzes of Agricultural engineering

Various concepts in c++ programming, including pointers, memory allocation using 'new' and 'delete' operations, and data structures such as linked lists, stacks, queues, and binary trees. Topics include pointer declarations, dynamic arrays of pointers, copy constructors, destructors, virtual functions, and recursive definitions. The document also discusses the importance of encapsulation, inheritance, and polymorphism in c++.

Typology: Quizzes

Pre 2010

Uploaded on 12/15/2009

riggins1
riggins1 🇺🇸

2 documents

1 / 10

Toggle sidebar

Related documents


Partial preview of the text

Download C++ Programming Concepts: Pointers, Memory Allocation, and Data Structures and more Quizzes Agricultural engineering in PDF only on Docsity! TERM 1 int *p p = &x cout DEFINITION 1 the memory address of x. TERM 2 when using the "delete" ... operation, the value must be a ... DEFINITION 2 pointer! TERM 3 make sure you declare some allocated space for pointers!!!! DEFINITION 3 ok TERM 4 flower ** pot; does what? DEFINITION 4 usually... creates a dynamic array of pointers of type flower. or a dynamic array of arrays of type flower. TERM 5 differences between passing by value, pointer, and reference. DEFINITION 5 passing by value is time-consuming and does not allow you to change the actual variable. passing by pointer is a syntactic burden, but allows you to change the variable. passing by reference (by using the ampersand) is quick and allows you to edit the object called at hand. TERM 6 How do we make an initializer list? (make a default constructor sphere with radius 1.0.) DEFINITION 6 sphere::sphere() (radius(1.0)){ //do nothing here. } this is preferred and quicker. TERM 7 Method and signature for copy constructor of a sphere with a radius and some atts DEFINITION 7 sphere::sphere(const sphere & orig){ theRadius = orig.theRadius; atts = new String[numAtts]; for(int i = 0; i < numAtts; i++){ atts[i] = orig.atts[i]; } } TERM 8 Destructor Method DEFINITION 8 Note: only can be used on pointers and arrays? maybe... I thought it was whenever you used 'new.' sphere::~sphere(){ delete []atts } be sure to delete all instance variables that are necessary! TERM 9 What does the operator= do, and how is it implemented? (with comments) DEFINITION 9 sphere & sphere::operator=(const sphere & rhs){ if(this != &rhs){ delete []atts; //delete what's already there in the old. radius = rhs.radius; //copy the values to make '='. numAtts = rhs.numAtts; atts = new String[numAtts]; for(int i = 0; i < numAtts; i++) atts[i] = rhs.atts[i]; { return *this; //return a helpful value. TERM 10 The Rule of the Big Three DEFINITION 10 If you make an assignment operator, a copy constructor, or a destructor, you MUST implement all three. also.... if a class has memeber variables that use dynamic memory, then you must use the big three. TERM 21 rules of interchanging queues and stacks. DEFINITION 21 queues cannot be stacks, but 2 stacks can totally make a queue. TERM 22 Everything you need to know about queues. DEFINITION 22 First in, first out queueing mechanism. Queues contain bool empty() const; void enqueue(const SIT & e); dequeue(); some queuenode with SIT data and queunode * next; member variables entry, exit, and size; TERM 23 Implementing Queues with linked lists DEFINITION 23 the exit should be at the head, and the entry should be at the tail. move entry and exit pointers around, don't shift data. this allows constant time for both enqueue and dequeue. TERM 24 Recursive definition for height of a tree DEFINITION 24 Height is the length of the longest path from a root to a leaf, and then you count the number of edges between them. if T is empty, height T = -1. if T is not empty, then height(T)=maxHeight(leftst, rightst)+1 TERM 25 if there are n data items in a binary tree, then how many pointers are null? DEFINITION 25 n + 1. TERM 26 Differentiate Full Binary Tree, complete/perfect binary tree, and balanced binary tree. DEFINITION 26 full binary tree: every node (not leaves) has 2 children. perfect binary tree: every level is FILLED. complete binary tree: every level is filled except the last, but the leaves are placed as far left as possible. balanced binary tree: depth/level of all the leaves are no greater than 1... when subtracted out. TERM 27 Preorder, inOrder, and postOrder Traversals DEFINITION 27 preorder: if(root) is not null, then yell, preorder the left, and preorder the right. inorder. preorder the right, yell, then prorder the left. postOrder: preorder both, then yell. TERM 28 copying and clearing a binary tree. DEFINITION 28 copy: make the root. if children exist, then copy the left tree, then copy the right tree. like preorder traversal. clear. if the root isn't null, clear the left subtree, clear the right subtree, then delete the root and set it to null. TERM 29 Breadth first/level order traversal. DEFINITION 29 look over them.... TERM 30 Define recursively a binary search tree. DEFINITION 30 Binary search tree is empty ... or... it consists of a root tgether with a left subtree and right subtree such that if x is in the left subtree, the x->data is smaller than the root's data. (or equal to) and if x is on the right, then its data is larger than that of the root. TERM 31 how do we check to see if a tree is a BST? DEFINITION 31 perform an in-order traversal. TERM 32 implementing find on a BST DEFINITION 32 if croot is null, return null; if croot == d return croot. if key < croot. find (the left) else //key > croot find (the right) TERM 33 implementing insert on BST. DEFINITION 33 if .... croot == null return null if croot->key == d then just return; it's already there. else... if croot->key is less, then insert the left subtree... else.... insert the right subtree. TERM 34 implementing remove on BST DEFINITION 34 0 child removal. who cares. 1-child removal. 2-child removal. swap with in-order predecessor, and then do the appropriate removal. note that the IOpredecessor is the rightmostCihld of cRoot's left subtree. TERM 35 Maximum number of nodes in a tree of height h? DEFINITION 35 2^(h+1) -1.
Docsity logo



Copyright © 2024 Ladybird Srl - Via Leonardo da Vinci 16, 10126, Torino, Italy - VAT 10816460017 - All rights reserved