int main() { int iRetVal = 0; Node *psRoot = NULL; GetNewNode(&psRoot, 10); AddLeftNode(psRoot,5); AddRightNode(psRoot,15); AddLeftNode(psRoot->psLeft,3); AddRightNode(psRoot->psLeft->psLeft,4); AddLeftNode(psRoot->psRight,13); AddRightNode(psRoot->psRight->psLeft,14); AddRightNode(psRoot->psRight,20); AddRightNode(psRoot->psRight->psRight,25); AddLeftNode(psRoot->psRight->psRight->psRight,22); PrintBoundry(psRoot); printf("\n"); SwapNodes(psRoot, 15, 13); PrintBoundry(psRoot); return iRetVal; }
void AddRightNode(Node *psRoot, int iData) { Node *psNewNode = NULL; GetNewNode(&psNewNode, iData); psRoot->psRight = psNewNode; }
void nuiFileTree::AddTree(const nglPath& rPath, bool Opened) { nuiTreeNodePtr pNode = GetNewNode(rPath); pNode->Open(Opened); mpTreeRoot->AddChild(pNode); mTrees[rPath] = pNode; }
//Inserts a Node at head of doubly linked list void InsertAtHead(struct command *cmd, struct linked_list *list) { struct Node* newNode = GetNewNode(cmd); if (list->head == NULL) { list->head = newNode; return; } list->head->prev = newNode; newNode->next = list->head; list->head = newNode; }
//Inserts a Node at head of doubly linked list void InsertAtHead(int x) { struct Node* newNode = GetNewNode(x); if(head == NULL) { head = newNode; return; } head->prev = newNode; newNode->next = head; head = newNode; }
//Inserts a Node at tail of Doubly linked list void InsertAtTail(struct command *cmd, struct linked_list *list) { struct Node* temp = list->head; struct Node* newNode = GetNewNode(cmd); if (list->head == NULL) { list->head = newNode; return; } while (temp->next != NULL) temp = temp->next; // Go To last Node temp->next = newNode; newNode->prev = temp; }
//Inserts a Node at tail of Doubly linked list void InsertAtTail(int x) { struct Node* temp = head; struct Node* newNode = GetNewNode(x); if(head == NULL) { head = newNode; return; } while(temp->next != NULL) temp = temp->next; // Go To last Node temp->next = newNode; newNode->prev = temp; }
struct node* Insert(struct node *root, int data) { if (root == NULL) root = GetNewNode(data); else if (data <= root->data) root->left = Insert(root->left, data); else root->right = Insert(root->right, data); return root; }
void InsertAtTail(char *scrntitle, void (*action)(void * parameter)) { node* temp = LCDList; node* newNode = GetNewNode(scrntitle, action); if ( LCDList == NULL) { LCDList = newNode; return; } while(temp->nextScreen != NULL) temp = temp->nextScreen; temp->nextScreen = newNode; newNode->prevScreen = temp; }
void InsertAtHead(char * scrntitle, void (*action)(void * parameter)) {// char * display; // display = strcenter(scrntitle,16); node* newNode = GetNewNode(scrntitle, action); if ( LCDList == NULL) { LCDList = newNode; return; } printf("%s",newNode->currScreen->displayline); LCDList->prevScreen = newNode; LCDList->nextScreen = LCDList; LCDList = newNode; }
// To insert data in BST, returns address of root node struct BstNode* Insert(struct BstNode* root,int data) {//pass by value therefore * used and reurn stmt.otherwise pbarg ** no return if(root == NULL) { // empty tree root = GetNewNode(data); } // if data to be inserted is lesser, insert in left subtree. else if(data <= root->data) { root->left = Insert(root->left,data); } // else, insert in right subtree. else { root->right = Insert(root->right,data); } return root; }
int main(int argc, char const *argv[]) { /*Driver code to test the implementation*/ node* head = NULL; // empty list. set head as NULL. head = GetNewNode(1); // Calling an Insert and printing list both in forward as well as reverse direction. InsertAtTail(2, head); Print(head); InsertAtTail(4, head); Print(head); InsertAtTail(8, head); Print(head); /* code */ return 0; }
BstNode* Insert(BstNode* root, int data) { if (root == NULL) { root = GetNewNode(data); } else if(data<=root->data) { root->left = Insert(root->left, data); } else { root->right = Insert(root->right, data); } return root; //return the root because root is local to main }
int main() { int iRetVal = 0; Node *psRoot = NULL; GetNewNode(&psRoot, 10); AddLeftNode(psRoot,5); AddRightNode(psRoot,15); AddLeftNode(psRoot->psLeft,3); AddRightNode(psRoot->psLeft->psLeft,4); AddLeftNode(psRoot->psRight,13); AddRightNode(psRoot->psRight->psLeft,14); AddRightNode(psRoot->psRight,20); AddRightNode(psRoot->psRight->psRight,25); AddLeftNode(psRoot->psRight->psRight->psRight,22); GetRightChild(psRoot,20); return iRetVal; }
void Push(int x) { struct node* newNode= GetNewNode(x); newNode->next=top; top=newNode; }
bool nuiFileTree::SetRootPath(const nglPath& rPath) { mRootPath = rPath; mEventSink.DisconnectAll(); if (mpFileBox) mpFileBox->Trash(); mpFileBox = new nuiVBox(2); mpFileBox->SetExpand(nuiExpandShrinkAndGrow); AddChild(mpFileBox); mpFileBox->SetCellMinPixels(0, FIRST_ROW_HEIGHT); mpScrollView = new nuiScrollView(true,true); mpFileBox->SetCell(1, mpScrollView); mpFileBox->SetCellExpand(1, nuiExpandShrinkAndGrow); if (rPath == nglPath(ROOTPATH_ALLVOLUMES)) { mpFileBox->SetCell(0, NULL); nuiTreeNodePtr pRoot = new nuiTreeNode(ROOTPATH_ALLVOLUMES); pRoot->Open(true); mpTreeView = new nuiTreeView(pRoot, false); mpTreeView->SetDeSelectable(false); mpTreeView->SetMultiSelectable(true); mpScrollView->AddChild(mpTreeView); std::list<nglPathVolume> volumes; nglPath::GetVolumes(volumes, nglPathVolume::All); std::list<nglPathVolume>::iterator it = volumes.begin(); std::list<nglPathVolume>::iterator end = volumes.end(); while (it != end) { const nglPathVolume vol(*it); nuiTreeNodePtr pNode = GetNewNode(vol.mPath); pRoot->AddChild(pNode); ++it; } mpTreeView->SetDragStartDelegate(nuiMakeDelegate(this, &nuiFileTree::OnDragStartDelegate)); mpTreeView->SetDragRequestDataDelegate(nuiMakeDelegate(this, &nuiFileTree::OnDragRequestDataDelegate)); mpTreeView->SetDragStopDelegate(nuiMakeDelegate(this, &nuiFileTree::OnDragStopDelegate)); return true; } // "go to parent folder" link nuiButton* pBtn = new nuiButton(); pBtn->SetPosition(nuiLeft); pBtn->SetObjectClass(_T("nuiFileTree::ParentFolderButton")); pBtn->SetObjectName(_T("nuiFileTree::ParentFolderButton")); pBtn->InvalidateLayout(); nuiImage* pIcon = new nuiImage(); pIcon->SetObjectName(_T("nuiFileTree::ParentFolderIcon")); pIcon->SetObjectClass(_T("nuiFileTree::ParentFolderIcon")); pBtn->AddChild(pIcon); // connect link to event mEventSink.Connect(pBtn->Activated, &nuiFileTree::OnGotoParentFolder); mpFileBox->SetCell(0, pBtn); nuiTreeNodePtr pNode = GetNewNode(rPath); if (pNode) { nuiTreeNodePtr pRoot = new nuiTreeNode(_T("HiddenRoot")); pRoot->AddChild(pNode); pRoot->Open(true); pNode->Open(true); mpTreeView = new nuiTreeView(pRoot, false); mpTreeView->SetDeSelectable(false); mpScrollView->AddChild(mpTreeView); } mpTreeView->SetDragStartDelegate(nuiMakeDelegate(this, &nuiFileTree::OnDragStartDelegate)); mpTreeView->SetDragRequestDataDelegate(nuiMakeDelegate(this, &nuiFileTree::OnDragRequestDataDelegate)); mpTreeView->SetDragStopDelegate(nuiMakeDelegate(this, &nuiFileTree::OnDragStopDelegate)); return true; }