#includeusing namespace std;int k = 0;struct FNode{ int *data;

#includeusing namespace std;int k = 0;struct FNode{ int *data; FNode **point; bool check; int n;}*root = NULL, *newNode = NULL, *x = NULL;void data(){ newNode = new FNode; newNode->data = new int5; newNode->point = new FNode *6; newNode->check = true; newNode->n = 0;}FNode * initialise(){ int i; data(); for (i = 0; i < 6; i++) {newNode->pointi = NULL;} return newNode;}void traverse(FNode *variable){ cout << endl; int j = 0; for (int i = 0; i < variable->n; i++) { if (variable->check == false) {traverse(variable->pointi);} cout << " " << variable->datai; j = i+j;} if (variable->check == false) {traverse(variable->pointj);} cout << endl;}void sort(int *variable, int n){ int temp; for (int i = 0; i < n; i++) { for (int j = i; j <= n; j++) { if (variablei > variablej) { //swapping temp = variablei; variablei = variablej; variablej = temp; } } }}int split_child(FNode *x, int i){ int j, middleChild; FNode *NewN, *NewN2, *y; NewN2 = initialise(); NewN2->check = true; if (i == -1) {middleChild = x->data2; x->data2 = 0; x->n–; NewN = initialise(); NewN->check = false; x->check = true; for (j = 3; j < 5; j++){ NewN2->dataj – 3 = x->dataj; NewN2->pointj – 3 = x->pointj; NewN2->n++; x->dataj = 0; x->n–; } for (j = 0; j<6; j++) { x->pointj = NULL; } NewN->data0 = middleChild; NewN->pointNewN->n = x; NewN->pointNewN->n + 1 = NewN2; NewN->n++; root = NewN; } else { y = x->pointi; middleChild = y->data2; y->data2 = 0; y->n–; for (j = 3; j < 5; j++) {NewN2->dataj – 3 = y->dataj; NewN2->n++; y->dataj = 0; y->n–;} x->pointi + 1 = y; x->pointi + 1 = NewN2; } return middleChild;}void insert(int a){ int i, temp; x = root; //CHECK ROOT FILLED OR NOT if (x == NULL) { root = initialise(); x = root; } //INSERTING NODES AFTER THE ROOT else { if (x->check == true && x->n == 5) { temp = split_child(x, -1); x = root; for (i = 0; i < (x->n); i++) { if ((a > x->datai) && (a < x->datai + 1)) {i++;break;} if (a < x->data0) {break;} } x = x->pointi; } else {//CHECK SEES THE NODE PRESENT while (x->check == false) { for (i = 0; i < (x->n); i++) { if ((a > x->datai) && (a < x->datai + 1)) {i++;break;} if (a < x->data0) {break;} } if ((x->pointi)->n == 5) { temp = split_child(x, i); x->datax->n = temp; x->n++; continue; } else {x = x->pointi;} } } } //SORTING EACH NODE AFTER INSERTING x->datax->n = a; sort(x->data, x->n); x->n++;}int main(){ int number,input,input1=0,y=0; bool dataCHeck = true; while (y == 0) { cout << "1. Enter the Elements." << endl; cout << "2. Display the sorted Fusion Tree" << endl; cout << "3. EXIT" << endl; cin >> input1; if (input1 == 1) { if (dataCHeck) { cout << "enter the no of elements to be inserted" << endl; cin >> number; cout << "Enter the sequence (each ekement 1 by 1)" << endl; for (int i = 0; i < number; i++) { cin >> input; insert(input); } dataCHeck = false; } else { cout << "data is entered" << endl; } } if (input1 == 2) { cout << "Data sorted in Fusion Tree" << endl; traverse(root); } if (input1==3) { y = 3; } } return 0;}

x

Hi!
I'm Neil!

Would you like to get a custom essay? How about receiving a customized one?

Check it out