Preview

Nt1310 Unit 1 Test Paper

Good Essays
Open Document
Open Document
381 Words
Grammar
Grammar
Plagiarism
Plagiarism
Writing
Writing
Score
Score
Nt1310 Unit 1 Test Paper
/*
Saad Nasir cs151028 3-A
1. Create an insert function that will take nodes and add them up in the binary tree.
2. Create Inorder, PostOrder and PreOrder traversal functions for the binary tree.
3. Create a binary search function that tells whether a given value exists in the tree or not.
4. Create a delete function that searches the value in the tree, if it is present it deletes that value and return true else return false.
BONUS: Create a Breadth first traversal function for the binary.

*/

#include
#include
using namespace std;

struct node
{
int data; node *left; node *right;

public:

node(void) : left(NULL),right(NULL) { }

node(int data) : data(data), right(NULL),left(NULL) { }

};

class binaryTree
{
public:
…show more content…
void PostOrder_print(node *p); void Search(int value); void Delete(int value);

void BreadthFirstTraversal(node* root);

};

binaryTree::binaryTree()
{
root=NULL;
}

binaryTree::~binaryTree()
{

}

void binaryTree::insert(int value,node *newNode) { int a=0;

if ( root == NULL ) { root = newNode; root->left=NULL; root->right=NULL; a++; } node *p=root; while(true) { if(a>=1) { break; } if ( value < p->data ) {

if(p->left==NULL) { p->left=newNode; break; } else if(p->left!=NULL) { p=p->left; }

} else if(value > p->data) { if(p->right==NULL) { p->right=newNode;

You May Also Find These Documents Helpful

  • Good Essays

    Nt1310 Unit 6 Paper

    • 368 Words
    • 2 Pages

    The stakeholder involved in this decision is Anne Distagne, the CEO of Linkage Construction, Inc. She was the individual involved in the decision-making process. of falsifying information to not display the significant increase in profit.…

    • 368 Words
    • 2 Pages
    Good Essays
  • Satisfactory Essays

    CS 220 – Programming w/ Data Structures: You have missed one assignment and one quiz. Your instructor has extended your assignment due date to this Sunday, April 10. Your instructor has also let you to take your Quiz # 2 during his office hours during this week. Let me know if you need additional support to study for this quiz. Your grade to date in this class is 30.2/37 81.62% B.…

    • 354 Words
    • 2 Pages
    Satisfactory Essays
  • Satisfactory Essays

    discrete math prob

    • 272 Words
    • 2 Pages

    3. Use a tree diagram to find the number of bit strings of length four with no…

    • 272 Words
    • 2 Pages
    Satisfactory Essays
  • Satisfactory Essays

    I. To find if there is any root to leaf path with specified sum in a binary tree.…

    • 359 Words
    • 2 Pages
    Satisfactory Essays
  • Good Essays

    Attribute grammar

    • 591 Words
    • 3 Pages

    Exercise 6.6 of the text contains a grammar that describes binary trees where each node of the tree has an integer label. It discusses an ordering requirement that is the same one required by binary search trees. Solve that exercise.…

    • 591 Words
    • 3 Pages
    Good Essays
  • Powerful Essays

    Systems Media Table

    • 1944 Words
    • 8 Pages

    Hierarchical databases place data into a structure that resembles a tree and allows for visual relationships to be used. There are tree arcs to show the flow of corresponding data. They are considered limited and inflexible showing a one-to-many flow such as in a genealogy tree. There can be only one parent segment per child (Englebardt & Nelson, 2002).…

    • 1944 Words
    • 8 Pages
    Powerful Essays
  • Satisfactory Essays

    Algorithm and Best Path

    • 261 Words
    • 2 Pages

    Backtracking is a general algorithm for finding all (or some) solutions to some computational problem, that incrementally builds candidates to the solutions, and abandons each partial candidate c ("backtracks") as soon as it determines that c cannot possibly be completed to a valid solution…

    • 261 Words
    • 2 Pages
    Satisfactory Essays
  • Powerful Essays

    The concept of a zerotree is introduced which identifies the parts of a tree that…

    • 2985 Words
    • 12 Pages
    Powerful Essays
  • Powerful Essays

    595 NSA

    • 7641 Words
    • 31 Pages

    6) A hierarchical database is designed with a tree-like structure that resembles a file system.…

    • 7641 Words
    • 31 Pages
    Powerful Essays
  • Better Essays

    Binary Search Tree

    • 1292 Words
    • 6 Pages

    //Program – Binary Search Tree #include<iostream> using namespace std; class node { public: int data; node *left, *right; node() { left=right=NULL; } node(int val) { left=right=NULL; data=val; } }; class bst { private: node *root; void insertNode(node *&rootptr, node *pnew); void deleteNode(node *&root, int delval); int least(node *rootptr); int max(node *rootptr); void pre(node *rootptr); void post(node *rootptr); void in(node *rootptr); int countinternal(node *rootptr, int &count); void printTree(node *p, int level); int search(node *rootptr, int data); public: bst(); void callsearch(int data); void insertBST(int datain); void deleteBST(int data); void displayin(); void displaypost(); void displaypre(); void count(); void print(); void leastele(); void maxele(); }; bst::bst() { root= NULL; } void bst::print() { printTree(root, 0); }; void bst::callsearch(int data) { search(root, data); } int bst::search(node *rootptr, int data) { if(rootptr==NULL) { cout<<"Data not found"; return 0; } else if(rootptr->data==data) cout<<"Element found"<<endl; else if(data<rootptr->data) search(rootptr->left, data); else search(rootptr->right, data); } void bst::count() { int c=0; cout<<"The number of internal nodes is: "<<countinternal(root, c)<<endl; } int bst::countinternal(node *rootptr,int &count) { if(rootptr!=NULL) { countinternal(rootptr->left, count); if(rootptr->right!=NULL || rootptr->left!=NULL)…

    • 1292 Words
    • 6 Pages
    Better Essays
  • Good Essays

    12.1-1 for the set of {1,4,5,10,16,17,21} of keys, draw binary search trees of height 2,3,4,5 and 6…

    • 1551 Words
    • 7 Pages
    Good Essays
  • Powerful Essays

    about dom in xml

    • 2907 Words
    • 12 Pages

    dynamic technology - a programmer can modify the contents of the tree structure, which essentially…

    • 2907 Words
    • 12 Pages
    Powerful Essays
  • Satisfactory Essays

    Data Structures

    • 312 Words
    • 2 Pages

    1. Introduction to algorithms [W.5,S.2] 2. Recursion [W.7,S.14] 3. Elementary data structures: stacks, queues, lists, and trees [S.3-8] 4. Sorting [W.8] 5. Searching [CLR.10,CLR.12,CLR.14] 6. Advanced data structures: balanced trees and heaps [S.9,S.11] 7. Graphs and their applications [S.12]…

    • 312 Words
    • 2 Pages
    Satisfactory Essays
  • Good Essays

    Linked list

    • 1308 Words
    • 6 Pages

    • Unary operator sizeof is used to determine the size in bytes of any data…

    • 1308 Words
    • 6 Pages
    Good Essays
  • Good Essays

    数据结构C语言版 串的块链存储表示和实现.txt成熟不是心变老,而是眼泪在眼里打转却还保持微笑。把一切平凡的事做好既不平凡,把一切简单的事做对既不简单。/* 数据结构C语言版 串的块链存储表示和实现 P78 编译环境:Dev-C++ 4.9.9.2 日期:2011年2月12日 */ #include #include #include #include // LString.h 串的块链存储表示 #define CHUNKSIZE 4 // 可由用户定义的块大小 typedef struct Chunk { char ch[CHUNKSIZE]; //块的数据域 struct Chunk *next; //块的指针域 }Chunk; typedef struct { Chunk *head, // 串的头指针 *tail; // 串的尾指针 int curlen; // 串的当前长度 }LString; char blank = '#'; // 全局变量,用于填补空余 // 初始化(产生空串)字符串T。 void InitString(LString *T) { (*T).curlen=0; (*T).head=…

    • 1320 Words
    • 6 Pages
    Good Essays