From 6e700710202e098b5bc6f9f419053a73336a3a24 Mon Sep 17 00:00:00 2001 From: sandy2004 <116422667+sandy2004@users.noreply.github.com> Date: Sun, 30 Oct 2022 18:38:37 +0530 Subject: [PATCH] Create trie.cpp --- trie.cpp | 83 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 83 insertions(+) create mode 100644 trie.cpp diff --git a/trie.cpp b/trie.cpp new file mode 100644 index 0000000..38eda57 --- /dev/null +++ b/trie.cpp @@ -0,0 +1,83 @@ +#include + +using namespace std; +class trie{ + + public: + char val; + bool end=false; + trie* children[26]={NULL}; +}; + +void insert(trie* root, string str) +{ + trie* temp=root; + for(int i=0; ichildren[str[i]-'a']) + { + temp->children[str[i]-'a']= new trie(); + } + temp=temp->children[str[i]-'a']; + } + temp->end=true; + cout<<"value successfully Inserted"<children[str[i]-'a']==NULL) + { + cout<<" Given value Not Found"<children[str[i]-'a']; + } + if(temp->end==true) + { + cout<<" Given value successfully Found"<children[str[i]-'a']==NULL) + { + cout<<"Given value is not present"<children[str[i]-'a']; + } + + if(temp->end==true) + { + temp->end=0; + cout<<"value successfully deleted"<>str; + insert(root,str); + search(root,str); + del(root,str); + return 0; +}