diff --git a/.DS_Store b/.DS_Store
index 02fc07e14..8a9e158f0 100644
Binary files a/.DS_Store and b/.DS_Store differ
diff --git a/.github/workflows/autolabel.yml b/.github/workflows/autolabel.yml
new file mode 100644
index 000000000..13ba80a5c
--- /dev/null
+++ b/.github/workflows/autolabel.yml
@@ -0,0 +1,62 @@
+name: Pull Request Messenger
+on:
+ pull_request:
+ types:
+ - opened
+
+jobs:
+ comment:
+ runs-on: ubuntu-latest
+ permissions:
+ contents: read
+ pull-requests: write
+
+ steps:
+ - uses: actions/github-script@v3
+ with:
+ github-token: ${{secrets.GITHUB_TOKEN}}
+ script: |
+ # Create comment body as Markdown
+
+ var msg = `👋 Thanks for participating! I will review as soon as possible, usually within a few hours.
+
+ **Watch for notifications** as I may request some small changes to make sure this meets the guidelines.`
+
+ # Get pull request description
+ var body = context.payload.pull_request.body
+
+ # If `body` exists, check for conditions
+ # related to being from a contributor
+ if(body) {
+ var isContribution = body.contains('New Submission')
+ var incompleteGuidelines = body.contains('[]')
+ }
+
+ if(isContribution) {
+ # Create comment
+ github.issues.createComment({
+ issue_number: context.issue.number,
+ owner: context.repo.owner,
+ repo: context.repo.repo,
+ body: msg
+ })
+
+ # Add 'hacktoberfest-accepted' label
+ github.issues.addLabels({
+ issue_number: context.issue.number,
+ owner: context.repo.owner,
+ repo: context.repo.repo,
+ labels: ['hacktoberfest-accepted']
+ })
+
+ # If missed checking guidelines,
+ # add 'invalid' label
+ if(incompleteGuidelines) {
+ github.issues.addLabels({
+ issue_number: context.issue.number,
+ owner: context.repo.owner,
+ repo: context.repo.repo,
+ labels: ['invalid']
+ })
+ }
+ }
diff --git a/.github/workflows/automerge.yml b/.github/workflows/automerge.yml
new file mode 100644
index 000000000..7a0fb41fb
--- /dev/null
+++ b/.github/workflows/automerge.yml
@@ -0,0 +1,14 @@
+name: automerge
+on:
+ pull_request:
+ types:
+ - labeled
+
+jobs:
+ automerge:
+ runs-on: ubuntu-latest
+ steps:
+ - name: automerge
+ uses: "pascalgn/automerge-action@v0.14.3"
+ env:
+ GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}"
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 000000000..7e1dc4cfc
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,5 @@
+# Add here the folders that not necessary.
+# Folders from the your IDE create automatically
+./.idea
+.vs
+.vscode
diff --git a/.idea/checkstyle-idea.xml b/.idea/checkstyle-idea.xml
new file mode 100644
index 000000000..e2be48c12
--- /dev/null
+++ b/.idea/checkstyle-idea.xml
@@ -0,0 +1,16 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/misc.xml b/.idea/misc.xml
index d56657add..99ae653d0 100644
--- a/.idea/misc.xml
+++ b/.idea/misc.xml
@@ -1,4 +1,4 @@
-
+
\ No newline at end of file
diff --git a/.idea/php.xml b/.idea/php.xml
new file mode 100644
index 000000000..31b8a3a3b
--- /dev/null
+++ b/.idea/php.xml
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.replit b/.replit
new file mode 100644
index 000000000..6134e302b
--- /dev/null
+++ b/.replit
@@ -0,0 +1,2 @@
+language = "undefined"
+run = ""
\ No newline at end of file
diff --git a/Android/Blood bank b/Android/Blood bank
new file mode 160000
index 000000000..d9f3dda0c
--- /dev/null
+++ b/Android/Blood bank
@@ -0,0 +1 @@
+Subproject commit d9f3dda0c54373a163d7a9ee653f0aba6db2c3be
diff --git a/Android/Retrofit demo/.gitignore b/Android/Retrofit demo/.gitignore
new file mode 100644
index 000000000..aa724b770
--- /dev/null
+++ b/Android/Retrofit demo/.gitignore
@@ -0,0 +1,15 @@
+*.iml
+.gradle
+/local.properties
+/.idea/caches
+/.idea/libraries
+/.idea/modules.xml
+/.idea/workspace.xml
+/.idea/navEditor.xml
+/.idea/assetWizardSettings.xml
+.DS_Store
+/build
+/captures
+.externalNativeBuild
+.cxx
+local.properties
diff --git a/Android/Retrofit demo/.idea/.gitignore b/Android/Retrofit demo/.idea/.gitignore
new file mode 100644
index 000000000..26d33521a
--- /dev/null
+++ b/Android/Retrofit demo/.idea/.gitignore
@@ -0,0 +1,3 @@
+# Default ignored files
+/shelf/
+/workspace.xml
diff --git a/Android/Retrofit demo/.idea/.name b/Android/Retrofit demo/.idea/.name
new file mode 100644
index 000000000..b3405b3b3
--- /dev/null
+++ b/Android/Retrofit demo/.idea/.name
@@ -0,0 +1 @@
+My Application
\ No newline at end of file
diff --git a/Android/Retrofit demo/.idea/compiler.xml b/Android/Retrofit demo/.idea/compiler.xml
new file mode 100644
index 000000000..61a9130cd
--- /dev/null
+++ b/Android/Retrofit demo/.idea/compiler.xml
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/Android/Retrofit demo/.idea/gradle.xml b/Android/Retrofit demo/.idea/gradle.xml
new file mode 100644
index 000000000..23a89bbb6
--- /dev/null
+++ b/Android/Retrofit demo/.idea/gradle.xml
@@ -0,0 +1,22 @@
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/Android/Retrofit demo/.idea/jarRepositories.xml b/Android/Retrofit demo/.idea/jarRepositories.xml
new file mode 100644
index 000000000..a5f05cd8c
--- /dev/null
+++ b/Android/Retrofit demo/.idea/jarRepositories.xml
@@ -0,0 +1,25 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/Android/Retrofit demo/.idea/misc.xml b/Android/Retrofit demo/.idea/misc.xml
new file mode 100644
index 000000000..d5d35ec44
--- /dev/null
+++ b/Android/Retrofit demo/.idea/misc.xml
@@ -0,0 +1,9 @@
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/Android/Retrofit demo/app/.gitignore b/Android/Retrofit demo/app/.gitignore
new file mode 100644
index 000000000..42afabfd2
--- /dev/null
+++ b/Android/Retrofit demo/app/.gitignore
@@ -0,0 +1 @@
+/build
\ No newline at end of file
diff --git a/Android/Retrofit demo/app/build.gradle b/Android/Retrofit demo/app/build.gradle
new file mode 100644
index 000000000..5463d1f79
--- /dev/null
+++ b/Android/Retrofit demo/app/build.gradle
@@ -0,0 +1,62 @@
+plugins {
+ id 'com.android.application'
+ id 'kotlin-android'
+}
+
+android {
+ compileSdkVersion 30
+ buildToolsVersion "31.0.0"
+
+ defaultConfig {
+ applicationId "com.example.retrofittut"
+ minSdkVersion 21
+ targetSdkVersion 30
+ versionCode 1
+ versionName "1.0"
+
+ testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
+ }
+ buildFeatures {
+ viewBinding true
+ }
+
+ buildTypes {
+ release {
+ minifyEnabled false
+ proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
+ }
+ }
+ compileOptions {
+ sourceCompatibility JavaVersion.VERSION_1_8
+ targetCompatibility JavaVersion.VERSION_1_8
+ }
+ kotlinOptions {
+ jvmTarget = '1.8'
+ }
+}
+
+dependencies {
+
+ implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
+ implementation 'androidx.core:core-ktx:1.6.0'
+ implementation 'androidx.appcompat:appcompat:1.3.1'
+ implementation 'com.google.android.material:material:1.4.0'
+ implementation 'androidx.constraintlayout:constraintlayout:2.1.0'
+ testImplementation 'junit:junit:'
+ androidTestImplementation 'androidx.test.ext:junit:1.1.3'
+ androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
+
+
+ // Retrofit
+ implementation 'com.squareup.retrofit2:retrofit:2.9.0'
+ implementation 'com.squareup.retrofit2:converter-gson:2.9.0'
+ implementation "com.squareup.okhttp3:okhttp:4.9.0"
+
+ // Coroutines
+ implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.5.0'
+ implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.4.1'
+
+ // Coroutine Lifecycle Scopes
+ implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:2.3.1"
+ implementation "androidx.lifecycle:lifecycle-runtime-ktx:2.3.1"
+}
\ No newline at end of file
diff --git a/Android/Retrofit demo/app/proguard-rules.pro b/Android/Retrofit demo/app/proguard-rules.pro
new file mode 100644
index 000000000..481bb4348
--- /dev/null
+++ b/Android/Retrofit demo/app/proguard-rules.pro
@@ -0,0 +1,21 @@
+# Add project specific ProGuard rules here.
+# You can control the set of applied configuration files using the
+# proguardFiles setting in build.gradle.
+#
+# For more details, see
+# http://developer.android.com/guide/developing/tools/proguard.html
+
+# If your project uses WebView with JS, uncomment the following
+# and specify the fully qualified class name to the JavaScript interface
+# class:
+#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
+# public *;
+#}
+
+# Uncomment this to preserve the line number information for
+# debugging stack traces.
+#-keepattributes SourceFile,LineNumberTable
+
+# If you keep the line number information, uncomment this to
+# hide the original source file name.
+#-renamesourcefileattribute SourceFile
\ No newline at end of file
diff --git a/Android/Retrofit demo/app/src/androidTest/java/com/example/retrofittut/ExampleInstrumentedTest.kt b/Android/Retrofit demo/app/src/androidTest/java/com/example/retrofittut/ExampleInstrumentedTest.kt
new file mode 100644
index 000000000..e94bbd5c1
--- /dev/null
+++ b/Android/Retrofit demo/app/src/androidTest/java/com/example/retrofittut/ExampleInstrumentedTest.kt
@@ -0,0 +1,24 @@
+package com.example.retrofittut
+
+import androidx.test.platform.app.InstrumentationRegistry
+import androidx.test.ext.junit.runners.AndroidJUnit4
+
+import org.junit.Test
+import org.junit.runner.RunWith
+
+import org.junit.Assert.*
+
+/**
+ * Instrumented test, which will execute on an Android device.
+ *
+ * See [testing documentation](http://d.android.com/tools/testing).
+ */
+@RunWith(AndroidJUnit4::class)
+class ExampleInstrumentedTest {
+ @Test
+ fun useAppContext() {
+ // Context of the app under test.
+ val appContext = InstrumentationRegistry.getInstrumentation().targetContext
+ assertEquals("com.example.retrofittut", appContext.packageName)
+ }
+}
\ No newline at end of file
diff --git a/Android/Retrofit demo/app/src/main/AndroidManifest.xml b/Android/Retrofit demo/app/src/main/AndroidManifest.xml
new file mode 100644
index 000000000..fc94dcbcc
--- /dev/null
+++ b/Android/Retrofit demo/app/src/main/AndroidManifest.xml
@@ -0,0 +1,22 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/Android/Retrofit demo/app/src/main/java/com/example/retrofittut/MainActivity.kt b/Android/Retrofit demo/app/src/main/java/com/example/retrofittut/MainActivity.kt
new file mode 100644
index 000000000..72be09091
--- /dev/null
+++ b/Android/Retrofit demo/app/src/main/java/com/example/retrofittut/MainActivity.kt
@@ -0,0 +1,55 @@
+package com.example.retrofittut
+
+import androidx.appcompat.app.AppCompatActivity
+import android.os.Bundle
+import android.util.Log
+import androidx.core.view.isVisible
+import androidx.lifecycle.lifecycleScope
+import androidx.recyclerview.widget.LinearLayoutManager
+import com.example.retrofittut.databinding.ActivityMainBinding
+import retrofit2.HttpException
+import java.io.IOException
+const val TAG = "MainAcctivity"
+class MainActivity : AppCompatActivity() {
+
+
+ lateinit var binding: ActivityMainBinding
+ private lateinit var todoAdapter : TodoAdapter
+ override fun onCreate(savedInstanceState: Bundle?) {
+ super.onCreate(savedInstanceState)
+ binding = ActivityMainBinding.inflate(layoutInflater)
+ setContentView(binding.root)
+ setupRecyclerView()
+
+ lifecycleScope.launchWhenCreated {
+ binding.progressBar.isVisible = true
+
+ val response = try {
+ RetrofitInstance.api.getTodos()
+ }catch (e : IOException){
+ binding.progressBar.isVisible = false
+ Log.e(TAG,"internet expection")
+ return@launchWhenCreated
+ }catch (e : HttpException){
+ binding.progressBar.isVisible = false
+ Log.e(TAG,"http expection , unexpexted")
+ return@launchWhenCreated
+ }
+
+ if (response.isSuccessful && response.body() != null ){
+ todoAdapter.todos = response.body()!!
+ }else {
+ Log.e(TAG, "Response not successful")
+ }
+ binding.progressBar.isVisible = false
+ }
+
+ }
+
+ private fun setupRecyclerView() = binding.rvTodos.apply {
+ todoAdapter = TodoAdapter()
+ adapter = todoAdapter
+ layoutManager = LinearLayoutManager(this@MainActivity)
+
+ }
+}
\ No newline at end of file
diff --git a/Android/Retrofit demo/app/src/main/java/com/example/retrofittut/RetrofitInstance.kt b/Android/Retrofit demo/app/src/main/java/com/example/retrofittut/RetrofitInstance.kt
new file mode 100644
index 000000000..5232afb5b
--- /dev/null
+++ b/Android/Retrofit demo/app/src/main/java/com/example/retrofittut/RetrofitInstance.kt
@@ -0,0 +1,15 @@
+package com.example.retrofittut
+
+import retrofit2.Retrofit
+import retrofit2.converter.gson.GsonConverterFactory
+
+object RetrofitInstance {
+
+ val api: ToDoApi by lazy {
+ Retrofit.Builder()
+ .baseUrl("https://jsonplaceholder.typicode.com")
+ .addConverterFactory(GsonConverterFactory.create())
+ .build()
+ .create(ToDoApi::class.java)
+ }
+}
diff --git a/Android/Retrofit demo/app/src/main/java/com/example/retrofittut/ToDoApi.kt b/Android/Retrofit demo/app/src/main/java/com/example/retrofittut/ToDoApi.kt
new file mode 100644
index 000000000..b9499ac38
--- /dev/null
+++ b/Android/Retrofit demo/app/src/main/java/com/example/retrofittut/ToDoApi.kt
@@ -0,0 +1,15 @@
+package com.example.retrofittut
+import retrofit2.Response
+import retrofit2.http.Body
+import retrofit2.http.GET
+import retrofit2.http.POST
+
+interface ToDoApi {
+
+ @GET("/todos")
+ // topass key use @Query("key"):Key : String
+ suspend fun getTodos():Response>
+
+// @POST("/createTodo")
+// fun createTodo(@Body todo: Todo): Response
+}
\ No newline at end of file
diff --git a/Android/Retrofit demo/app/src/main/java/com/example/retrofittut/Todo.kt b/Android/Retrofit demo/app/src/main/java/com/example/retrofittut/Todo.kt
new file mode 100644
index 000000000..88cdf5142
--- /dev/null
+++ b/Android/Retrofit demo/app/src/main/java/com/example/retrofittut/Todo.kt
@@ -0,0 +1,8 @@
+package com.example.retrofittut
+
+data class Todo(
+ val completed: Boolean,
+ val id: Int,
+ val title: String,
+ val userId: Int
+)
\ No newline at end of file
diff --git a/Android/Retrofit demo/app/src/main/java/com/example/retrofittut/TodoAdapter.kt b/Android/Retrofit demo/app/src/main/java/com/example/retrofittut/TodoAdapter.kt
new file mode 100644
index 000000000..43d85f9f7
--- /dev/null
+++ b/Android/Retrofit demo/app/src/main/java/com/example/retrofittut/TodoAdapter.kt
@@ -0,0 +1,50 @@
+package com.example.retrofittut
+
+import android.view.LayoutInflater
+import android.view.ViewGroup
+import androidx.recyclerview.widget.AsyncListDiffer
+import androidx.recyclerview.widget.DiffUtil
+import androidx.recyclerview.widget.RecyclerView
+import com.example.retrofittut.databinding.IteaTodosBinding
+
+class TodoAdapter : RecyclerView.Adapter() {
+
+ inner class TodoViewHolder(val binding: IteaTodosBinding):RecyclerView.ViewHolder(binding.root)
+
+ private val diffCallback = object : DiffUtil.ItemCallback() {
+ override fun areItemsTheSame(oldItem: Todo, newItem: Todo): Boolean {
+ return oldItem.id == newItem.id
+ }
+
+ override fun areContentsTheSame(oldItem: Todo, newItem: Todo): Boolean {
+ return oldItem == newItem
+ }
+ }
+
+ private val differ = AsyncListDiffer(this, diffCallback)
+ var todos: List
+ get() = differ.currentList
+ set(value) { differ.submitList(value) }
+
+ override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): TodoViewHolder {
+ return TodoViewHolder(IteaTodosBinding.inflate(
+ LayoutInflater.from(parent.context),
+ parent,
+ false
+ ))
+ }
+
+ override fun onBindViewHolder(holder: TodoViewHolder, position: Int) {
+ holder.binding.apply {
+ val todo = todos[position]
+ tvTitle.text = todo.title
+ checkBox.isChecked = todo.completed
+ }
+ }
+
+ override fun getItemCount(): Int {
+ return todos.size
+ }
+
+
+}
\ No newline at end of file
diff --git a/Android/Retrofit demo/app/src/main/res/drawable-v24/ic_launcher_foreground.xml b/Android/Retrofit demo/app/src/main/res/drawable-v24/ic_launcher_foreground.xml
new file mode 100644
index 000000000..2b068d114
--- /dev/null
+++ b/Android/Retrofit demo/app/src/main/res/drawable-v24/ic_launcher_foreground.xml
@@ -0,0 +1,30 @@
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/Android/Retrofit demo/app/src/main/res/drawable/ic_launcher_background.xml b/Android/Retrofit demo/app/src/main/res/drawable/ic_launcher_background.xml
new file mode 100644
index 000000000..07d5da9cb
--- /dev/null
+++ b/Android/Retrofit demo/app/src/main/res/drawable/ic_launcher_background.xml
@@ -0,0 +1,170 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/Android/Retrofit demo/app/src/main/res/layout/activity_main.xml b/Android/Retrofit demo/app/src/main/res/layout/activity_main.xml
new file mode 100644
index 000000000..86e05156e
--- /dev/null
+++ b/Android/Retrofit demo/app/src/main/res/layout/activity_main.xml
@@ -0,0 +1,30 @@
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/Android/Retrofit demo/app/src/main/res/layout/itea_todos.xml b/Android/Retrofit demo/app/src/main/res/layout/itea_todos.xml
new file mode 100644
index 000000000..8a89b398f
--- /dev/null
+++ b/Android/Retrofit demo/app/src/main/res/layout/itea_todos.xml
@@ -0,0 +1,28 @@
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/Android/Retrofit demo/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml b/Android/Retrofit demo/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml
new file mode 100644
index 000000000..eca70cfe5
--- /dev/null
+++ b/Android/Retrofit demo/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml
@@ -0,0 +1,5 @@
+
+
+
+
+
\ No newline at end of file
diff --git a/Android/Retrofit demo/app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml b/Android/Retrofit demo/app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml
new file mode 100644
index 000000000..eca70cfe5
--- /dev/null
+++ b/Android/Retrofit demo/app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml
@@ -0,0 +1,5 @@
+
+
+
+
+
\ No newline at end of file
diff --git a/Android/Retrofit demo/app/src/main/res/mipmap-hdpi/ic_launcher.png b/Android/Retrofit demo/app/src/main/res/mipmap-hdpi/ic_launcher.png
new file mode 100644
index 000000000..a571e6009
Binary files /dev/null and b/Android/Retrofit demo/app/src/main/res/mipmap-hdpi/ic_launcher.png differ
diff --git a/Android/Retrofit demo/app/src/main/res/mipmap-hdpi/ic_launcher_round.png b/Android/Retrofit demo/app/src/main/res/mipmap-hdpi/ic_launcher_round.png
new file mode 100644
index 000000000..61da551c5
Binary files /dev/null and b/Android/Retrofit demo/app/src/main/res/mipmap-hdpi/ic_launcher_round.png differ
diff --git a/Android/Retrofit demo/app/src/main/res/mipmap-mdpi/ic_launcher.png b/Android/Retrofit demo/app/src/main/res/mipmap-mdpi/ic_launcher.png
new file mode 100644
index 000000000..c41dd2853
Binary files /dev/null and b/Android/Retrofit demo/app/src/main/res/mipmap-mdpi/ic_launcher.png differ
diff --git a/Android/Retrofit demo/app/src/main/res/mipmap-mdpi/ic_launcher_round.png b/Android/Retrofit demo/app/src/main/res/mipmap-mdpi/ic_launcher_round.png
new file mode 100644
index 000000000..db5080a75
Binary files /dev/null and b/Android/Retrofit demo/app/src/main/res/mipmap-mdpi/ic_launcher_round.png differ
diff --git a/Android/Retrofit demo/app/src/main/res/mipmap-xhdpi/ic_launcher.png b/Android/Retrofit demo/app/src/main/res/mipmap-xhdpi/ic_launcher.png
new file mode 100644
index 000000000..6dba46dab
Binary files /dev/null and b/Android/Retrofit demo/app/src/main/res/mipmap-xhdpi/ic_launcher.png differ
diff --git a/Android/Retrofit demo/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png b/Android/Retrofit demo/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png
new file mode 100644
index 000000000..da31a871c
Binary files /dev/null and b/Android/Retrofit demo/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png differ
diff --git a/Android/Retrofit demo/app/src/main/res/mipmap-xxhdpi/ic_launcher.png b/Android/Retrofit demo/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
new file mode 100644
index 000000000..15ac68172
Binary files /dev/null and b/Android/Retrofit demo/app/src/main/res/mipmap-xxhdpi/ic_launcher.png differ
diff --git a/Android/Retrofit demo/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png b/Android/Retrofit demo/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png
new file mode 100644
index 000000000..b216f2d31
Binary files /dev/null and b/Android/Retrofit demo/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png differ
diff --git a/Android/Retrofit demo/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png b/Android/Retrofit demo/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
new file mode 100644
index 000000000..f25a41974
Binary files /dev/null and b/Android/Retrofit demo/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png differ
diff --git a/Android/Retrofit demo/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png b/Android/Retrofit demo/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png
new file mode 100644
index 000000000..e96783ccc
Binary files /dev/null and b/Android/Retrofit demo/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png differ
diff --git a/Android/Retrofit demo/app/src/main/res/values-night/themes.xml b/Android/Retrofit demo/app/src/main/res/values-night/themes.xml
new file mode 100644
index 000000000..203e2191b
--- /dev/null
+++ b/Android/Retrofit demo/app/src/main/res/values-night/themes.xml
@@ -0,0 +1,16 @@
+
+
+
+
\ No newline at end of file
diff --git a/Android/Retrofit demo/app/src/main/res/values/colors.xml b/Android/Retrofit demo/app/src/main/res/values/colors.xml
new file mode 100644
index 000000000..f8c6127d3
--- /dev/null
+++ b/Android/Retrofit demo/app/src/main/res/values/colors.xml
@@ -0,0 +1,10 @@
+
+
+ #FFBB86FC
+ #FF6200EE
+ #FF3700B3
+ #FF03DAC5
+ #FF018786
+ #FF000000
+ #FFFFFFFF
+
\ No newline at end of file
diff --git a/Android/Retrofit demo/app/src/main/res/values/strings.xml b/Android/Retrofit demo/app/src/main/res/values/strings.xml
new file mode 100644
index 000000000..3de1a3968
--- /dev/null
+++ b/Android/Retrofit demo/app/src/main/res/values/strings.xml
@@ -0,0 +1,3 @@
+
+ My Application
+
\ No newline at end of file
diff --git a/Android/Retrofit demo/app/src/main/res/values/themes.xml b/Android/Retrofit demo/app/src/main/res/values/themes.xml
new file mode 100644
index 000000000..eebc2d049
--- /dev/null
+++ b/Android/Retrofit demo/app/src/main/res/values/themes.xml
@@ -0,0 +1,16 @@
+
+
+
+
\ No newline at end of file
diff --git a/Android/Retrofit demo/app/src/test/java/com/example/retrofittut/ExampleUnitTest.kt b/Android/Retrofit demo/app/src/test/java/com/example/retrofittut/ExampleUnitTest.kt
new file mode 100644
index 000000000..aa30c8030
--- /dev/null
+++ b/Android/Retrofit demo/app/src/test/java/com/example/retrofittut/ExampleUnitTest.kt
@@ -0,0 +1,17 @@
+package com.example.retrofittut
+
+import org.junit.Test
+
+import org.junit.Assert.*
+
+/**
+ * Example local unit test, which will execute on the development machine (host).
+ *
+ * See [testing documentation](http://d.android.com/tools/testing).
+ */
+class ExampleUnitTest {
+ @Test
+ fun addition_isCorrect() {
+ assertEquals(4, 2 + 2)
+ }
+}
\ No newline at end of file
diff --git a/Android/Retrofit demo/build.gradle b/Android/Retrofit demo/build.gradle
new file mode 100644
index 000000000..4709739c3
--- /dev/null
+++ b/Android/Retrofit demo/build.gradle
@@ -0,0 +1,26 @@
+// Top-level build file where you can add configuration options common to all sub-projects/modules.
+buildscript {
+ ext.kotlin_version = "1.4.32"
+ repositories {
+ google()
+ jcenter()
+ }
+ dependencies {
+ classpath "com.android.tools.build:gradle:4.1.0"
+ classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
+
+ // NOTE: Do not place your application dependencies here; they belong
+ // in the individual module build.gradle files
+ }
+}
+
+allprojects {
+ repositories {
+ google()
+ jcenter()
+ }
+}
+
+task clean(type: Delete) {
+ delete rootProject.buildDir
+}
\ No newline at end of file
diff --git a/Android/Retrofit demo/gradle.properties b/Android/Retrofit demo/gradle.properties
new file mode 100644
index 000000000..98bed167d
--- /dev/null
+++ b/Android/Retrofit demo/gradle.properties
@@ -0,0 +1,21 @@
+# Project-wide Gradle settings.
+# IDE (e.g. Android Studio) users:
+# Gradle settings configured through the IDE *will override*
+# any settings specified in this file.
+# For more details on how to configure your build environment visit
+# http://www.gradle.org/docs/current/userguide/build_environment.html
+# Specifies the JVM arguments used for the daemon process.
+# The setting is particularly useful for tweaking memory settings.
+org.gradle.jvmargs=-Xmx2048m -Dfile.encoding=UTF-8
+# When configured, Gradle will run in incubating parallel mode.
+# This option should only be used with decoupled projects. More details, visit
+# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
+# org.gradle.parallel=true
+# AndroidX package structure to make it clearer which packages are bundled with the
+# Android operating system, and which are packaged with your app"s APK
+# https://developer.android.com/topic/libraries/support-library/androidx-rn
+android.useAndroidX=true
+# Automatically convert third-party libraries to use AndroidX
+android.enableJetifier=true
+# Kotlin code style for this project: "official" or "obsolete":
+kotlin.code.style=official
\ No newline at end of file
diff --git a/Android/Retrofit demo/gradle/wrapper/gradle-wrapper.jar b/Android/Retrofit demo/gradle/wrapper/gradle-wrapper.jar
new file mode 100644
index 000000000..f6b961fd5
Binary files /dev/null and b/Android/Retrofit demo/gradle/wrapper/gradle-wrapper.jar differ
diff --git a/Android/Retrofit demo/gradle/wrapper/gradle-wrapper.properties b/Android/Retrofit demo/gradle/wrapper/gradle-wrapper.properties
new file mode 100644
index 000000000..21daf05b3
--- /dev/null
+++ b/Android/Retrofit demo/gradle/wrapper/gradle-wrapper.properties
@@ -0,0 +1,6 @@
+#Sun Sep 12 11:48:53 IST 2021
+distributionBase=GRADLE_USER_HOME
+distributionPath=wrapper/dists
+zipStoreBase=GRADLE_USER_HOME
+zipStorePath=wrapper/dists
+distributionUrl=https\://services.gradle.org/distributions/gradle-6.5-bin.zip
diff --git a/Android/Retrofit demo/gradlew b/Android/Retrofit demo/gradlew
new file mode 100644
index 000000000..cccdd3d51
--- /dev/null
+++ b/Android/Retrofit demo/gradlew
@@ -0,0 +1,172 @@
+#!/usr/bin/env sh
+
+##############################################################################
+##
+## Gradle start up script for UN*X
+##
+##############################################################################
+
+# Attempt to set APP_HOME
+# Resolve links: $0 may be a link
+PRG="$0"
+# Need this for relative symlinks.
+while [ -h "$PRG" ] ; do
+ ls=`ls -ld "$PRG"`
+ link=`expr "$ls" : '.*-> \(.*\)$'`
+ if expr "$link" : '/.*' > /dev/null; then
+ PRG="$link"
+ else
+ PRG=`dirname "$PRG"`"/$link"
+ fi
+done
+SAVED="`pwd`"
+cd "`dirname \"$PRG\"`/" >/dev/null
+APP_HOME="`pwd -P`"
+cd "$SAVED" >/dev/null
+
+APP_NAME="Gradle"
+APP_BASE_NAME=`basename "$0"`
+
+# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
+DEFAULT_JVM_OPTS=""
+
+# Use the maximum available, or set MAX_FD != -1 to use that value.
+MAX_FD="maximum"
+
+warn () {
+ echo "$*"
+}
+
+die () {
+ echo
+ echo "$*"
+ echo
+ exit 1
+}
+
+# OS specific support (must be 'true' or 'false').
+cygwin=false
+msys=false
+darwin=false
+nonstop=false
+case "`uname`" in
+ CYGWIN* )
+ cygwin=true
+ ;;
+ Darwin* )
+ darwin=true
+ ;;
+ MINGW* )
+ msys=true
+ ;;
+ NONSTOP* )
+ nonstop=true
+ ;;
+esac
+
+CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
+
+# Determine the Java command to use to start the JVM.
+if [ -n "$JAVA_HOME" ] ; then
+ if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
+ # IBM's JDK on AIX uses strange locations for the executables
+ JAVACMD="$JAVA_HOME/jre/sh/java"
+ else
+ JAVACMD="$JAVA_HOME/bin/java"
+ fi
+ if [ ! -x "$JAVACMD" ] ; then
+ die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
+
+Please set the JAVA_HOME variable in your environment to match the
+location of your Java installation."
+ fi
+else
+ JAVACMD="java"
+ which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
+
+Please set the JAVA_HOME variable in your environment to match the
+location of your Java installation."
+fi
+
+# Increase the maximum file descriptors if we can.
+if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then
+ MAX_FD_LIMIT=`ulimit -H -n`
+ if [ $? -eq 0 ] ; then
+ if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
+ MAX_FD="$MAX_FD_LIMIT"
+ fi
+ ulimit -n $MAX_FD
+ if [ $? -ne 0 ] ; then
+ warn "Could not set maximum file descriptor limit: $MAX_FD"
+ fi
+ else
+ warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
+ fi
+fi
+
+# For Darwin, add options to specify how the application appears in the dock
+if $darwin; then
+ GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
+fi
+
+# For Cygwin, switch paths to Windows format before running java
+if $cygwin ; then
+ APP_HOME=`cygpath --path --mixed "$APP_HOME"`
+ CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
+ JAVACMD=`cygpath --unix "$JAVACMD"`
+
+ # We build the pattern for arguments to be converted via cygpath
+ ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
+ SEP=""
+ for dir in $ROOTDIRSRAW ; do
+ ROOTDIRS="$ROOTDIRS$SEP$dir"
+ SEP="|"
+ done
+ OURCYGPATTERN="(^($ROOTDIRS))"
+ # Add a user-defined pattern to the cygpath arguments
+ if [ "$GRADLE_CYGPATTERN" != "" ] ; then
+ OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
+ fi
+ # Now convert the arguments - kludge to limit ourselves to /bin/sh
+ i=0
+ for arg in "$@" ; do
+ CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
+ CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
+
+ if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
+ eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
+ else
+ eval `echo args$i`="\"$arg\""
+ fi
+ i=$((i+1))
+ done
+ case $i in
+ (0) set -- ;;
+ (1) set -- "$args0" ;;
+ (2) set -- "$args0" "$args1" ;;
+ (3) set -- "$args0" "$args1" "$args2" ;;
+ (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
+ (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
+ (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
+ (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
+ (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
+ (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
+ esac
+fi
+
+# Escape application args
+save () {
+ for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done
+ echo " "
+}
+APP_ARGS=$(save "$@")
+
+# Collect all arguments for the java command, following the shell quoting and substitution rules
+eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS"
+
+# by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong
+if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then
+ cd "$(dirname "$0")"
+fi
+
+exec "$JAVACMD" "$@"
diff --git a/Android/Retrofit demo/gradlew.bat b/Android/Retrofit demo/gradlew.bat
new file mode 100644
index 000000000..f9553162f
--- /dev/null
+++ b/Android/Retrofit demo/gradlew.bat
@@ -0,0 +1,84 @@
+@if "%DEBUG%" == "" @echo off
+@rem ##########################################################################
+@rem
+@rem Gradle startup script for Windows
+@rem
+@rem ##########################################################################
+
+@rem Set local scope for the variables with windows NT shell
+if "%OS%"=="Windows_NT" setlocal
+
+set DIRNAME=%~dp0
+if "%DIRNAME%" == "" set DIRNAME=.
+set APP_BASE_NAME=%~n0
+set APP_HOME=%DIRNAME%
+
+@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
+set DEFAULT_JVM_OPTS=
+
+@rem Find java.exe
+if defined JAVA_HOME goto findJavaFromJavaHome
+
+set JAVA_EXE=java.exe
+%JAVA_EXE% -version >NUL 2>&1
+if "%ERRORLEVEL%" == "0" goto init
+
+echo.
+echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
+echo.
+echo Please set the JAVA_HOME variable in your environment to match the
+echo location of your Java installation.
+
+goto fail
+
+:findJavaFromJavaHome
+set JAVA_HOME=%JAVA_HOME:"=%
+set JAVA_EXE=%JAVA_HOME%/bin/java.exe
+
+if exist "%JAVA_EXE%" goto init
+
+echo.
+echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
+echo.
+echo Please set the JAVA_HOME variable in your environment to match the
+echo location of your Java installation.
+
+goto fail
+
+:init
+@rem Get command-line arguments, handling Windows variants
+
+if not "%OS%" == "Windows_NT" goto win9xME_args
+
+:win9xME_args
+@rem Slurp the command line arguments.
+set CMD_LINE_ARGS=
+set _SKIP=2
+
+:win9xME_args_slurp
+if "x%~1" == "x" goto execute
+
+set CMD_LINE_ARGS=%*
+
+:execute
+@rem Setup the command line
+
+set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
+
+@rem Execute Gradle
+"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
+
+:end
+@rem End local scope for the variables with windows NT shell
+if "%ERRORLEVEL%"=="0" goto mainEnd
+
+:fail
+rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
+rem the _cmd.exe /c_ return code!
+if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
+exit /b 1
+
+:mainEnd
+if "%OS%"=="Windows_NT" endlocal
+
+:omega
diff --git a/Android/Retrofit demo/settings.gradle b/Android/Retrofit demo/settings.gradle
new file mode 100644
index 000000000..8cedfc042
--- /dev/null
+++ b/Android/Retrofit demo/settings.gradle
@@ -0,0 +1,2 @@
+include ':app'
+rootProject.name = "My Application"
\ No newline at end of file
diff --git a/Android/git b/Android/git
new file mode 100644
index 000000000..e69de29bb
diff --git a/Arduino/Firebase_Home_Automation/Firebase_Home_Automation.ino b/Arduino/Firebase_Home_Automation/Firebase_Home_Automation.ino
new file mode 100644
index 000000000..ac307080e
--- /dev/null
+++ b/Arduino/Firebase_Home_Automation/Firebase_Home_Automation.ino
@@ -0,0 +1,48 @@
+#include
+#include
+#include
+#include
+ #include
+
+// Set these to run example.
+#define FIREBASE_HOST "smart-home-f5995-default-rtdb.firebaseio.com"
+#define FIREBASE_AUTH "AxKFBFQR4F4294UvzSy1Am34dR3oN8R9JsSlDkX"
+#define WIFI_SSID "0opsyProxy :-)"
+#define WIFI_PASSWORD "12345678"
+
+String myString;
+int vr = A0; // variable resistor connected
+int sdata = 0; // The variable resistor value will be stored in sdata.
+
+void setup()
+{
+ // Debug console
+ Serial.begin(9600);
+ pinMode(vr ,INPUT);
+ // connect to wifi.
+ pinMode(D0,OUTPUT);
+ WiFi.begin(WIFI_SSID, WIFI_PASSWORD);
+ Serial.print("connecting");
+ while (WiFi.status() != WL_CONNECTED)
+ {
+ Serial.print(".");
+ delay(500);
+ }
+ Serial.println();
+ Serial.print("connected: ");
+ Serial.println(WiFi.localIP());
+
+ Firebase.begin(FIREBASE_HOST, FIREBASE_AUTH);
+
+ Firebase.setString("Variable/Value","smart-home-f5995-default-rtdb");
+}
+
+void loop()
+{
+
+sdata = analogRead(vr);
+myString = String(sdata);
+Serial.println(myString);
+Firebase.setString("Variable/Value",myString);
+delay(1000);
+}
diff --git a/C#/SinglyLinkedList.cs b/C#/SinglyLinkedList.cs
new file mode 100644
index 000000000..f7e48523f
--- /dev/null
+++ b/C#/SinglyLinkedList.cs
@@ -0,0 +1,182 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace SinglyLinkedList
+{
+ class Node
+ {
+ public int data;
+ public Node next;
+
+ public Node(int value)
+ {
+ data = value;
+ next = null;
+ }
+ }
+
+ class LinkedList
+ {
+ private Node head;
+ public int length;
+
+ public void AddNodeToFront(int value)
+ {
+ Node nodeToAdd = new Node(value);
+ nodeToAdd.next = head;
+ head = nodeToAdd;
+ length++;
+ }
+
+ public void AppendToLast(int value)
+ {
+ if (head == null)
+ {
+ head = new Node(value);
+ head.next = null;
+ length++;
+ }
+ else
+ {
+ Node nodeToAdd = new Node(value);
+ Node current = head;
+
+ while (current.next != null)
+ {
+ current = current.next;
+ }
+ current.next = nodeToAdd;
+ length++;
+ }
+ }
+
+ public void Insert(int index, int value)
+ {
+ if (index == 0)
+ {
+ AddNodeToFront(value);
+ }
+ else if (index >= length)
+ {
+ AppendToLast(value);
+ }
+ else
+ {
+ int counter = 0;
+ Node newNode = new Node(value);
+ Node pointer = head;
+ Node temp;
+ length++;
+
+ while(pointer != null)
+ {
+ if (counter == index - 1)
+ {
+ temp = pointer.next;
+ pointer.next = newNode;
+ newNode.next = temp;
+ break;
+ }
+ else
+ {
+ pointer = pointer.next;
+ counter++;
+ }
+ }
+ }
+ }
+
+ public void Remove(int index)
+ {
+ if (index == 0)
+ {
+ Node current = head.next;
+ head.next = null;
+ head = current;
+ length--;
+ }
+ else
+ {
+ if (index >= length)
+ index = length - 1;
+
+ Node current = head;
+ int counter = 0;
+ Node temp;
+
+ while (current != null)
+ {
+ if (counter == index - 1)
+ {
+ temp = current.next;
+ current.next = temp.next;
+ length--;
+ break;
+ }
+ else
+ {
+ current = current.next;
+ counter++;
+ }
+ }
+ }
+ }
+
+ public void Reverse()
+ {
+ if (length > 1)
+ {
+ Node first = head;
+ Node second = first.next;
+ Node temp;
+
+ while (second != null)
+ {
+ temp = second.next;
+ second.next = first;
+ first = second;
+ second = temp;
+ }
+
+ head.next = null;
+ head = first;
+ }
+ }
+
+ public void PrintAllNodes()
+ {
+ Node point = head;
+
+ while (point != null)
+ {
+ Console.WriteLine(point.data);
+ point = point.next;
+ }
+ }
+ }
+
+ class Program
+ {
+ static void Main(string[] args)
+ {
+ LinkedList myLinkedList = new LinkedList();
+ myLinkedList.AddNodeToFront(8);
+ myLinkedList.AppendToLast(7);
+ myLinkedList.AppendToLast(6);
+ myLinkedList.Insert(2, 4);
+ myLinkedList.Insert(3, 12);
+ myLinkedList.Remove(1);
+ Console.WriteLine("Linked list before reversal:");
+ myLinkedList.PrintAllNodes();
+ myLinkedList.Reverse();
+ Console.WriteLine("Linked list after reversal:");
+ myLinkedList.PrintAllNodes();
+ Console.WriteLine("Length of the linked list: {0}", myLinkedList.length);
+
+ Console.Read();
+ }
+ }
+}
diff --git a/C/BFS_DFS.c b/C/BFS_DFS.c
new file mode 100644
index 000000000..43077b784
--- /dev/null
+++ b/C/BFS_DFS.c
@@ -0,0 +1,159 @@
+#include
+
+int q[20],top=-1,front=-1,rear=-1,a[20][20],vis[20],stack[20];
+int delete();
+void add(int item);
+void bfs(int s,int n);
+void dfs(int s,int n);
+void push(int item);
+int pop();
+
+void main()
+{
+int n,i,s,ch,j;
+char c,dummy;
+printf("ENTER THE NUMBER VERTICES ");
+scanf("%d",&n);
+for(i=1;i<=n;i++)
+{
+for(j=1;j<=n;j++)
+{
+printf("ENTER 1 IF %d HAS A NODE WITH %d ELSE 0 ",i,j);
+scanf("%d",&a[i][j]);
+}
+}
+printf("THE ADJACENCY MATRIX IS\n");
+for(i=1;i<=n;i++)
+{
+for(j=1;j<=n;j++)
+{
+printf(" %d",a[i][j]);
+}
+printf("\n");
+}
+
+do
+{
+for(i=1;i<=n;i++)
+vis[i]=0;
+printf("\nMENU");
+printf("\n1.B.F.S");
+printf("\n2.D.F.S");
+printf("\nENTER YOUR CHOICE");
+scanf("%d",&ch);
+printf("ENTER THE SOURCE VERTEX :");
+scanf("%d",&s);
+
+switch(ch)
+{
+case 1:bfs(s,n);
+break;
+case 2:
+dfs(s,n);
+break;
+}
+printf("DO U WANT TO CONTINUE(Y/N) ? ");
+scanf("%c",&dummy);
+scanf("%c",&c);
+}while((c=='y')||(c=='Y'));
+}
+
+
+//**************BFS(breadth-first search) code**************//
+void bfs(int s,int n)
+{
+int p,i;
+add(s);
+vis[s]=1;
+p=delete();
+if(p!=0)
+printf(" %d",p);
+while(p!=0)
+{
+for(i=1;i<=n;i++)
+if((a[p][i]!=0)&&(vis[i]==0))
+{
+add(i);
+vis[i]=1;
+}
+p=delete();
+if(p!=0)
+printf(" %d ",p);
+}
+for(i=1;i<=n;i++)
+if(vis[i]==0)
+bfs(i,n);
+}
+
+
+void add(int item)
+{
+if(rear==19)
+printf("QUEUE FULL");
+else
+{
+if(rear==-1)
+{
+q[++rear]=item;
+front++;
+}
+else
+q[++rear]=item;
+}
+}
+int delete()
+{
+int k;
+if((front>rear)||(front==-1))
+return(0);
+else
+{
+k=q[front++];
+return(k);
+}
+}
+
+
+//***************DFS(depth-first search) code******************//
+void dfs(int s,int n)
+{
+int i,k;
+push(s);
+vis[s]=1;
+k=pop();
+if(k!=0)
+printf(" %d ",k);
+while(k!=0)
+{
+for(i=1;i<=n;i++)
+if((a[k][i]!=0)&&(vis[i]==0))
+{
+push(i);
+vis[i]=1;
+}
+k=pop();
+if(k!=0)
+printf(" %d ",k);
+}
+for(i=1;i<=n;i++)
+if(vis[i]==0)
+dfs(i,n);
+}
+void push(int item)
+{
+if(top==19)
+printf("Stack overflow ");
+else
+stack[++top]=item;
+}
+int pop()
+{
+int k;
+if(top==-1)
+return(0);
+else
+{
+k=stack[top--];
+return(k);
+}
+}
diff --git a/C/BinarySearchTree.c b/C/BinarySearchTree.c
new file mode 100644
index 000000000..189a88642
--- /dev/null
+++ b/C/BinarySearchTree.c
@@ -0,0 +1,98 @@
+#include
+#include
+struct node
+{
+ int data;
+ struct node *left;
+ struct node *right;
+};
+struct node *root;
+struct node *makenode(int x)
+{
+ struct node *p;
+ p=(struct node *)malloc(sizeof(struct node));
+ p->data=x;
+ p->left=NULL;
+ p->right=NULL;
+ return p;
+}
+int BSTinsert(int key)
+{
+ struct node *x,*y,*z;
+ x=root;
+ y=makenode(key);
+ while(x!=NULL)
+ {
+ z=x;
+ if(x->dataright;
+ else
+ x=x->left;
+ }
+ if(keydata)
+ z->left=y;
+ else
+ z->right=y;
+}
+int BSTmin(struct node *s)
+{
+ while(s->left!=NULL)
+ {
+ s=s->left;
+ }
+ return s->data;
+}
+int BSTmax(struct node *s)
+{
+ while(s->right!=NULL)
+ {
+ s=s->right;
+ }
+ return s->data;
+}
+struct node *BSTsearch(int key)
+{
+ struct node *t;
+ t=root;
+ while(t!=NULL)
+ {
+ if(t->data==key)
+ return t;
+ else
+ {
+ if(keydata)
+ t=t->left;
+ else
+ t=t->right;
+ }
+ }
+ return NULL;
+}
+int InOrdertraversal(struct node *t)
+{
+ if(t!=NULL)
+ {
+ InOrdertraversal(t->left);
+ printf(" %d",t->data);
+ InOrdertraversal(t->right);
+ }
+}
+void main()
+{
+ int A[]={13,45,23,67,56,93,72,18,35};
+ root=NULL;
+ root=makenode(A[0]);
+ for(int i=1;i<9;i++)
+ {
+ BSTinsert(A[i]);
+ }
+ printf("Elements in the binary search tree ->");
+ InOrdertraversal(root);
+ int p=BSTmax(root);
+ printf("\nMax Element->%d",p);
+ p=BSTmin(root);
+ printf("\nMin Element->%d",p);
+ struct node *r=BSTsearch(56);
+ printf("\nSearched element is present at %u",r);
+ printf("\nSearched element->%d",r->data);
+}
diff --git a/C/Binary_Search.c b/C/Binary_Search.c
index 4e53537de..1a78bceca 100644
--- a/C/Binary_Search.c
+++ b/C/Binary_Search.c
@@ -32,6 +32,7 @@ int main(void)
int arr[] = { 2, 3, 4, 10, 40 };
int n = sizeof(arr) / sizeof(arr[0]);
int x = 10;
+ //Calling the binarySearch function
int result = binarySearch(arr, 0, n - 1, x);
(result == -1) ? printf("Element is not present"
" in array")
diff --git a/C/Bucket_Sort.c b/C/Bucket_Sort.c
new file mode 100644
index 000000000..1ad7b0cd8
--- /dev/null
+++ b/C/Bucket_Sort.c
@@ -0,0 +1,53 @@
+// Bucket Sort in C programming
+
+#include
+int getMax(int array[], int size)
+{
+ int max = array[0];
+ for (int i = 1; i < size; i++)
+ if (array[i] > max)
+ max = array[i];
+ return max;
+}
+void bucketSort(int array[], int size)
+{
+ // The size of bucket must be at least the (max+1) but
+ // we cannot assign declare it as int bucket(max+1) in C as
+ // it does not support dynamic memory allocation.
+ // So, its size is provided statically.
+
+ int bucket[10];
+ const int max = getMax(array, size);
+ for (int i = 0; i <= max; i++)
+ {
+ bucket[i] = 0;
+ }
+ for (int i = 0; i < size; i++)
+ {
+ bucket[array[i]]++;
+ }
+ for (int i = 0, j = 0; i <= max; i++)
+ {
+ while (bucket[i] > 0)
+ {
+ array[j++] = i;
+ bucket[i]--;
+ }
+ }
+}
+void printArray(int array[], int size)
+{
+ for (int i = 0; i < size; ++i)
+ {
+ printf("%d ", array[i]);
+ }
+ printf("\n");
+}
+int main()
+{
+ int data[] = {4, 3, 4, 5, 6, 0, 9, 5};
+ int size = sizeof(data) / sizeof(data[0]);
+ bucketSort(data, size);
+ printf("Sorted array in ascending order: \n");
+ printArray(data, size);
+}
\ No newline at end of file
diff --git a/C/Diary Management/Diary Management.c b/C/Diary Management/Diary Management.c
new file mode 100644
index 000000000..f956f4689
--- /dev/null
+++ b/C/Diary Management/Diary Management.c
@@ -0,0 +1,828 @@
+#include
+#include
+#include
+#include
+
+int login();
+void addMeet();
+void addBlog();
+void deleteMeet();
+void deleteBlog();
+void viewMeet();
+void viewBlog();
+void editMeet();
+void editBlog();
+void changePassword();
+
+struct database{
+ char time[6];
+ char date[15];
+ char name[30];
+ char place[25];
+ char duration[10];
+ char note[500];
+};
+
+int main(){
+ int access = login();
+ if(access){
+ int ch; char logout[3];
+ for(;;){
+ system("cls");
+ printf("\033[0;34m************************************************************************************\n");
+ printf("\t\t\t\tPersonal Diary\n");
+ printf("************************************************************************************\033[0m\n");
+ printf("\t\t\t\t\033[0;35m[1] Add Meet\n");
+ printf("\t\t\t\t[2] Delete Meet\n");
+ printf("\t\t\t\t[3] Add Blog\n");
+ printf("\t\t\t\t[4] Delete Blog\n");
+ printf("\t\t\t\t[5] Edit Meet\n");
+ printf("\t\t\t\t[6] Edit Blog\n");
+ printf("\t\t\t\t[7] Meet View\n");
+ printf("\t\t\t\t[8] Blog View\n");
+ printf("\t\t\t\t[9] Change Password\n");
+ printf("\t\t\t\t[0] Logout \n");
+ printf("\t\t\t\t Enter choice: \033[0m");
+ scanf("%d",&ch);
+ switch(ch){
+ case 1: addMeet(); break;
+ case 2: deleteMeet(); break;
+ case 3: addBlog(); break;
+ case 4: deleteBlog(); break;
+ case 5: editMeet(); break;
+ case 6: editBlog(); break;
+ case 7: viewMeet(); break;
+ case 8: viewBlog(); break;
+ case 9: changePassword(); break;
+ case 0: printf("\n\n\t\t\t\t\033[0;31m Are you sure? (YES/NO) : \033[0m");
+ scanf("%s",logout);
+ if(strcmp(logout,"YES")==0){
+ printf("\n\t\t\t\t\033[0;32mThanks for choosing my application :)\033[0m\n"); return 0;
+ }else break;
+ default: printf("\t\t\t\tYou pressed wrong key!!!\n\n\n");
+ }
+ }
+ }
+}
+
+int login(){
+ char username[20], confirm[20]={0}, pass[15]={0};
+ int i;
+ FILE *fp;
+ for(int j=0; j<3; j++)
+ {
+ i=0;
+ system("cls");
+ printf("\033[0;34m************************************************************************************\n");
+ printf("\t\t\t\tLogin\n");
+ printf("************************************************************************************\033[0m\n");
+ printf("\n\n\t\t\033[0;31mPLEASE NOTE YOU HAVE ONLY THREE CHANCES TO LOGIN\n\t\t\t ENTER YOUR PASSWORD CAREFULLY\n");
+ printf("\n\n\tAttempt(s) Left : \033[0m%d\n",3-j);
+ printf("\n\n\t\t\033[0;35mENTER USERNAME : \033[m");
+ gets(username);
+ printf("\t\t\033[0;35mENTER THE PASSWORD : \033[m");
+ do{
+ pass[i]=getch(); //STORES VALUE IN getch() AND PRINTS STAR(*)
+ if(pass[i]!='\r')
+ printf("*");
+ i++;
+ }while(pass[i-1]!='\r');
+ pass[i-1]='\0';
+
+ fp = fopen("login.txt","r");
+ if(fp==NULL){
+ printf("\n\033[0;31mError with the login file...[MISSING]\033[m\n");
+ getch();
+ return 0;
+ }
+ else{
+ i=0;
+ while(1){
+ char c=fgetc(fp);
+ if(c==EOF){
+ confirm[i]='\0';
+ break;
+ }
+ confirm[i]=c;
+ i++;
+ }
+ }
+
+ if(strcmp(pass,confirm)==0){
+ printf("\n\n\t\t\t\t\033[0;32mACCESS GRANTED...\n\033[0m");
+ printf("\n\t\t\t\t\033[0;33mPress Any key...\033[0m");
+ getch();
+ return 1;
+ }
+ else{
+ printf("\n\n\t\t\t\t\033[0;31mWRONG PASSWORD... ACCESS DENIED\n");
+ printf("\n\n\t\t Press Any Key To Retry... Attempts Left : \033[0m%d",3-j-1);
+ getch();
+ }
+
+ }
+ printf("\n\n\t\t\033[0;31m::YOUR 3 ATTEMPTS GOT EXHAUSTED::YOU ARE NOT ALLOWED TO ACCESS ANY FILE::\n\n\t\t\t\tPRESS ANY KEY TO GO BACK...\033[0m");
+ getch();
+ return 0;
+}
+
+void addMeet(){
+ system("cls");
+ FILE *fp ;
+ char another = 'Y' ,time[10];
+ struct database e ;
+ char filename[15];
+ int choice;
+ printf("\033[0;34m************************************************************************************\n");
+ printf("\t\t\t\tWelcome To Meet Menu\n");
+ printf("************************************************************************************\033[m\n");
+
+ printf("\n\n\t\t\t\033[0;35mENTER DATE OF YOUR RECORD:[yyyy-mm-dd]:\033[0m");
+ fflush(stdin);
+ gets(filename);
+
+ fp = fopen (filename, "a+" ); //OPENS FILE IN APPEND MODE AND IF IT DOESN'T EXISTS, THEN CREATES FILE
+ if(fp==NULL){
+ fp=fopen(filename,"w+");
+ if(fp==NULL) {
+ printf("\n\t\t\t\t\033[0;31mSYSTEM ERROR...");
+ printf("\n\t\t\t\tPRESS ANY KEY TO EXIT\033[0m");
+ getch();
+ return ;
+ }
+ }
+
+ while ( another == 'Y'|| another=='y' ){
+ choice=0;
+ fflush(stdin); //CLEARS ALL THE PAST INPUTS FROM THE BUFFER TO AVOID MIS FETCHING
+ printf ( "\n\t\t\t\t\033[0;35mENTER TIME:[hh:mm]:\033[0m");
+ scanf("%s",time);
+ rewind(fp); //SETS FILE POINTER TO BEGIN OF FILE AND CLEARS EOF OR ERRORS PRESENT IN FILE
+ while(fread(&e,sizeof(e),1,fp)==1) //READS DATA FROM GIVEN STREAM USING POINTER
+ {
+ if(strcmp(e.time,time)==0)
+ {
+ printf("\n\t\t\t\t\033[0;31mTHE RECORD ALREADY EXISTS.\033[0m\n");
+ choice=1;
+ }
+ }
+
+ if(choice==0)
+ {
+ strcpy(e.time,time);
+ printf("\t\t\t\t\033[0;35mENTER NAME: \033[0m");
+ fflush(stdin);
+ gets(e.name);
+ fflush(stdin);
+ printf("\t\t\t\t\033[0;35mENTER PLACE: \033[0m");
+ gets(e.place);
+ fflush(stdin);
+ printf("\t\t\t\t\033[0;35mENTER DURATION: \033[0m");
+ gets(e.duration);
+ fflush(stdin);
+ printf("\t\t\t\t\033[0;35mNOTE: \033[0m");
+ gets(e.note);
+ fwrite( &e,sizeof(e),1,fp); //WRITES DATA FROM ARRAY POINTER TO, BY POINTER TO THE GIVEN STREAM
+ printf("\n\n\t\t\t\t\033[0;32mYOUR RECORD IS ADDED...\033[0m\n");
+ }
+
+ printf ( "\n\t\t\t\t\033[0;35mADD ANOTHER RECORD...(Y/N)\033[0m " ) ;
+ fflush ( stdin ) ;
+ another = getchar(); //TAKES ONLY ONE LETTER AS INPUT AND IGNORES REST
+
+ }
+
+
+
+ fclose ( fp ) ;
+ printf("\n\n\t\t\t\t\033[0;33mPRESS ANY KEY TO EXIT...\033[0m");
+ getch();
+}
+
+void addBlog(){
+ system("cls");
+ FILE *fp ;
+ char another = 'Y' ,time[10];
+ struct database e ;
+ char filename[15];
+ int choice,flg;
+ printf("\033[0;34m************************************************************************************\n");
+ printf("\t\t\t\tWelcome To Blog Menu\n");
+ printf("************************************************************************************\033[m\n");
+ nm: printf("\n\n\t\t\t\033[0;35mENTER BLOG NAME: \033[0m");
+ fflush(stdin);
+ gets(filename);
+
+ fp = fopen (filename, "a+" ); //OPENS FILE IN APPEND MODE AND IF IT DOESN'T EXISTS, THEN CREATES FILE
+ if(fp==NULL){
+ fp=fopen(filename,"w+");
+ if(fp==NULL) {
+ printf("\n\033[0;31mSYSTEM ERROR...");
+ printf("\nPRESS ANY KEY TO EXIT\033[0m");
+ getch();
+ return ;
+ }
+ }
+
+ do{
+ flg=1;
+ while(fread(&e,sizeof(e),1,fp)==1){
+ if(strcmp(e.date,filename)==0){
+ flg=0;
+ printf("\t\t\033[0;31mRecord Exists... Either make different one or edit earlier one\033[0m\n");
+ goto nm;
+ }
+ }
+ }while(flg==0);
+
+ while ( another == 'Y'|| another=='y' ){
+ choice=0;
+
+ rewind(fp); //SETS FILE POINTER TO BEGIN OF FILE AND CLEARS EOF OR ERRORS PRESENT IN FILE
+
+ if(choice==0)
+ {
+ strcpy(e.date,filename);
+ fflush(stdin);
+ printf("\t\t\t\t\t\t\033[0;35mADD TODAY's BLOG...\033[0m\n\n");
+ gets(e.note);
+ fwrite( &e,sizeof(e),1,fp); //WRITES DATA FROM ARRAY POINTER TO, BY POINTER TO THE GIVEN STREAM
+ printf("\n\n\t\t\t\t\033[0;32mYOUR BLOG IS ADDED...\033[0m\n");
+ }
+
+ printf ( "\n\t\t\t\t\033[0;35mADD ANOTHER BLOG...(Y/N) \033[0m" ) ;
+ fflush ( stdin ) ;
+ another = getchar(); //TAKES ONLY ONE LETTER AS INPUT AND IGNORES REST
+
+ }
+}
+
+void deleteMeet(){
+ system("cls");
+ FILE *fp,*fptr ;
+ struct database file ;
+ char filename[15],another = 'Y' ,time[10];;
+ int choice,check;
+
+ printf("\033[0;34m************************************************************************************\n");
+ printf("\t\t\t\tWelcome To Delete Menu\n");
+ printf("************************************************************************************\033[m\n");
+
+ while(another == 'Y')
+ {
+ printf("\n\n\t\t\t\t\033[0;35mHOW WOULD YOU LIKE TO DELETE");
+ printf("\n\n\t\t\t\t[1] DELETE WHOLE RECORD");
+ printf("\n\t\t\t\t[2] DELETE A PARTICULAR RECORD BY TIME");
+
+ do
+ {
+ printf("\n\t\t\t\tENTER YOU CHOICE: \033[0m");
+ scanf("%d",&choice);
+ switch(choice)
+ {
+ case 1:
+ printf("\n\t\t\t\t\033[0;35mENTER THE DATE OF RECORD TO BE DELETED:[yyyy-mm-dd]: \033[0m");
+ fflush(stdin);
+ gets(filename);
+ fp = fopen (filename, "wb" ) ;
+ if ( fp == NULL )
+ {
+ printf("\n\t\t\t\t\033[0;31mTHE FILE DOES NOT EXISTS");
+ printf("\n\n\t\t\t\tPRESS ANY KEY TO GO BACK.\033[0m");
+ getch();
+ return ;
+ }
+ fclose(fp);
+ remove(filename);
+ printf("\n\n\t\t\t\t\033[0;32m%s DELETED SUCCESFULLY...\033[0m",filename);
+ break;
+
+ case 2:
+ printf("\n\t\t\t\t\033[0;35mENTER THE DATE OF RECORD:[yyyy-mm-dd]: \033[0m");
+ fflush(stdin);
+ gets(filename);
+ fp = fopen (filename, "rb" ) ;
+ if ( fp == NULL )
+ {
+ printf("\n\t\t\t\t\033[0;31mTHE FILE DOES NOT EXISTS");
+ printf("\n\n\t\t\t\tPRESS ANY KEY TO GO BACK.\033[0m");
+ getch();
+ return ;
+ }
+ fptr=fopen("temp","wb");
+ if(fptr==NULL)
+ {
+ printf("\n\t\t\t\t\033[0;31mSYSTEM ERROR");
+ printf("\n\t\t\t\tPRESS ANY KEY TO GO BACK\033[0m");
+ getch();
+ return ;
+ }
+ printf("\n\n\t\t\t\t\033[0;35mENTER THE TIME OF RECORD TO BE DELETED:[hh:mm]: \033[0m");
+ fflush(stdin);
+ gets(time);
+
+ while(fread(&file,sizeof(file),1,fp)==1)
+ {
+ if(strcmp(file.time,time)!=0)
+ fwrite(&file,sizeof(file),1,fptr);
+ }
+ fclose(fp);
+ fclose(fptr);
+ remove(filename);
+ rename("temp",filename);
+ printf("\n\n\t\t\t\t\033[0;32mSCHEDULE AT %s ON %s DELETED SUCCESFULLY...\033[0m",time,filename);
+ break;
+
+ default:
+ printf("\n\t\t\t\t\033[0;31mYOU ENTERED WRONG CHOICE\033[0m");
+ break;
+ }
+ }
+ while(choice<1||choice>2);
+
+ printf("\n\n\t\t\t\t\033[0;35mDO YOU LIKE TO DELETE ANOTHER RECORD.(Y/N): \033[0m");
+ fflush(stdin);
+ scanf("%c",&another);
+ }
+
+ printf("\n\n\t\t\t\t\033[0;33mPRESS ANY KEY TO EXIT...\033[0m");
+ getch();
+}
+
+void deleteBlog(){
+ system("cls");
+ FILE *fp,*fptr ;
+ struct database file ;
+ char filename[15],another = 'Y' ,time[10];;
+ int choice,check;
+
+ while(another == 'Y')
+ {
+ system("cls");
+ printf("\033[0;34m************************************************************************************\n");
+ printf("\t\t\t\tWelcome To Delete Menu\n");
+ printf("************************************************************************************\033[m\n");
+ printf("\n\t\t\t\t\033[0;35mENTER THE BLOG TO BE DELETED: \033[0m");
+ fflush(stdin);
+ gets(filename);
+ fp = fopen (filename, "r" ) ;
+ if ( fp == NULL )
+ {
+ printf("\n\t\t\t\t\033[0;31mTHE FILE DOES NOT EXISTS");
+ printf("\n\n\t\t\t\tPRESS ANY KEY TO GO BACK.\033[0m");
+ getch();
+ return ;
+ }
+ fclose(fp);
+ remove(filename);
+ printf("\n\n\t\t\t\t\033[0;32m%s DELETED SUCCESFULLY...\033[0m",filename);
+
+ printf("\n\n\t\t\t\t\033[0;35mDO YOU LIKE TO DELETE ANOTHER RECORD.(Y/N): \033[0m");
+ fflush(stdin);
+ scanf("%c",&another);
+ }
+
+ printf("\n\n\t\t\t\t\033[0;33mPRESS ANY KEY TO EXIT...\033[0m");
+ getch();
+}
+
+void viewMeet(){
+ FILE *fp;
+ system("cls");
+ struct database customer;
+ char time[6],choice,filename[14];
+ int ch,flg=0;
+ printf("\033[0;34m************************************************************************************\n");
+ printf("\t\t\t\tWelcome To Meet View Menu\n");
+ printf("************************************************************************************\033[m\n");
+
+ do{
+ printf("\n\t\t\033[0;35mENTER THE DATE OF RECORD TO BE VIEWED:[yyyy-mm-dd]: \033[0m");
+ fflush(stdin);
+ gets(filename);
+ fp = fopen (filename, "rb" );
+
+ if (fp == NULL){
+ puts ( "\n\t\t\t\t\033[0;31mTHE RECORD DOES NOT EXIST...\n" ) ;
+ printf("\t\t\t\tPRESS ANY KEY TO EXIT...\033[0m");
+ getch();
+ return ;
+ }
+
+ system("cls");
+ printf("\n\t\t\t\t\033[0;35mHOW WOULD YOU LIKE TO VIEW:\n");
+ printf("\n\t\t\t\t[1] WHOLE MEET'S PLANNED FOR THE DAY.");
+ printf("\n\t\t\t\t[2] RECORD OF FIX TIME.");
+ printf("\n\t\t\t\t ENTER YOUR CHOICE: \033[0m");
+ scanf("%d",&ch);
+ switch(ch){
+ case 1:
+ printf("\n\t\t\t\t\033[0;36mTHE WHOLE RECORD FOR %s IS: ",filename);
+ while ( fread ( &customer, sizeof ( customer ), 1, fp) == 1 )
+ {
+ printf("\n");
+ printf("\n\t\t\t\tTIME: %s",customer.time);
+ printf("\n\t\t\t\tMEETING WITH: %s",customer.name);
+ printf("\n\t\t\t\tMEETING AT: %s",customer.place);
+ printf("\n\t\t\t\tDURATION: %s",customer.duration);
+ printf("\n\t\t\t\tNOTE: %s",customer.note);
+ printf("\n");
+ }
+ printf("\033[0m");
+ break;
+
+ case 2:
+ fflush(stdin);
+ printf("\n\t\t\t\t\033[0;35mENTER TIME:[hh:mm]: \033[0m");
+ gets(time);
+ while ( fread ( &customer, sizeof ( customer ), 1, fp) == 1 )
+ {
+ if(strcmp(customer.time,time)==0)
+ {
+ printf("\n\t\t\t\t\033[0;36mYOUR RECORD IS:");
+ printf("\n\t\t\t\tTIME: %s",customer.time);
+ printf("\n\t\t\t\tMEETING WITH: %s",customer.name);
+ printf("\n\t\t\t\tMEETING AT: %s",customer.place);
+ printf("\n\t\t\t\tDUARATION: %s",customer.duration);
+ printf("\n\t\t\t\tNOTE: %s",customer.note);
+ printf("\033[0m");
+ flg=1;
+ }
+ }
+ if(flg!=1)
+ printf("\n\t\t\t\t\033[0;31mNo such meet scheduled\n\033[0m");
+ break;
+
+ default:
+ printf("\n\t\t\t\t\033[0;31mYOU TYPED SOMETHING ELSE...\033[0m\n");
+ break;
+ }
+
+ printf("\n\n\t\t\t\t\033[0;35mWOULD YOU LIKE TO CONTINUE VIEWING...(Y/N):\033[0m");
+
+ fflush(stdin);
+
+ choice = getchar();
+ system("cls");
+
+ }while(choice=='Y'||choice=='y');
+
+ fclose (fp);
+ return ;
+}
+
+void editBlog(){
+ system("cls");
+ FILE *fp ;
+ struct database e ;
+ char time[6],choice,filename[14];
+ int num,count=0;
+
+ do
+ {
+ printf("\033[0;34m************************************************************************************\n");
+ printf("\t\t\t\tWelcome To Editing Menu\n");
+ printf("************************************************************************************\033[m\n");
+ printf("\n\n\t\t\033[0;35mENTER THE BLOG NAME TO BE EDITED: \033[0m");
+ fflush(stdin);
+ gets(filename);
+
+ fp = fopen ( filename, "rb+" );
+
+ if ( fp == NULL )
+ {
+ printf("\n\t\t\t\t\033[0;31mRECORD DOES NOT EXISTS: ");
+ printf("\n\t\t\t\tPRESS ANY KEY TO GO BACK\033[0m");
+ getch();
+ return;
+ }
+
+ while ( fread ( &e, sizeof ( e ), 1, fp ) == 1 )
+ {
+ printf("\n\t\t\t\033[0;36mYOUR OLD RECORD WAS AS:");
+ printf("\nFILE NAME: %s\n",e.date);
+ printf("\nBLOG: %s\n\n",e.note);
+
+ printf("\033[0m\n\t\033[0;35mENTER NEW BLOG: \033[0m\n");
+ fflush(stdin);
+ gets(e.note);
+ }
+
+ fseek(fp,-sizeof(e),SEEK_CUR);
+ fwrite(&e,sizeof(e),1,fp);
+ fseek(fp,-sizeof(e),SEEK_CUR);
+ fread(&e,sizeof(e),1,fp);
+ choice=5;
+
+
+
+ if(choice==5)
+ {
+ system("cls");
+ printf("\n\t\t\t\t\033[0;32mEDITING COMPLETED...\n\n\n");
+ printf("\033[0;36m-------------------------------------------------------------------------------------\n");
+ printf("\t\t\t\tTHE NEW RECORD IS:\n");
+ printf("-------------------------------------------------------------------------------------\n");
+ printf("\n\t\t\t\tFILE NAME: %s\n",e.date);
+ printf("\n\t\t\t\tBLOG: %s",e.note);
+ fclose(fp);
+ printf("\033[0m\n\n\t\t\t\t\033[m\033[0;35mWOULD YOU LIKE TO EDIT ANOTHER RECORD.(Y/N)\033[0m");
+ scanf("%c",&choice);
+ count++;
+ }
+
+ }
+ while(choice=='Y'||choice=='y');
+
+ fclose ( fp );
+
+ if(count==1)
+ printf("\n\t\t\t\t\033[0;32m%d FILE IS EDITED...\n\n\n",count);
+ else if(count>1)
+ printf("\n\t\t\t\t%d FILES ARE EDITED..\n\n\n",count);
+ else
+ printf("\n\t\t\t\tNO FILES EDITED...\n\n\n");
+
+ printf("\t\t\t\t\033[0m\033[0;33mPRESS ANY KEY TO EXIT...\033[0m");
+ getch();
+}
+
+void viewBlog(){
+ FILE *fp;
+ system("cls");
+ struct database customer;
+ char time[6],choice,filename[14];
+ int ch;
+ printf("\033[0;34m************************************************************************************\n");
+ printf("\t\t\t\tWelcome To Blog View Menu\n");
+ printf("************************************************************************************\033[m\n");
+
+ do{
+ printf("\n\t\t\033[0;35mENTER THE BLOG NAME TO BE VIEWED: \033[0m");
+ fflush(stdin);
+ gets(filename);
+ fp = fopen (filename, "rb" );
+
+ if (fp == NULL){
+ puts ( "\n\t\t\t\t\033[0;31mTHE BLOG DOES NOT EXIST...\n" ) ;
+ printf("\t\t\t\tPRESS ANY KEY TO EXIT...\033[0m");
+ getch();
+ return ;
+ }
+
+
+ printf("\n\t\t\t\t\033[0;36mTHE BLOG NAME IS: %s",filename);
+ while ( fread ( &customer, sizeof ( customer ), 1, fp) == 1 )
+ {
+ printf("\n");
+ printf("\n\t\t\t\tBLOG: %s",customer.note);
+ printf("\033[0m\n");
+ }
+
+ printf("\n\n\t\t\t\t\033[0;35mWOULD YOU LIKE TO CONTINUE VIEWING...(Y/N): \033[0m");
+
+ fflush(stdin);
+
+ choice = getchar();
+ system("cls");
+
+ }while(choice=='Y'||choice=='y');
+
+ fclose (fp);
+ return ;
+}
+
+void editMeet(){
+ system("cls");
+ FILE *fp ;
+ struct database e ;
+ char time[6],choice,filename[14];
+ int num,count=0;
+
+ printf("\033[0;34m************************************************************************************\n");
+ printf("\t\t\t\tWelcome To Editing Menu\n");
+ printf("************************************************************************************\033[m\n");
+
+ do
+ {
+ printf("\n\n\t\t\033[0;35mENTER THE RECORD TO BE EDITED:[yyyy:mm:dd]: \033[0m");
+ fflush(stdin);
+ gets(filename);
+
+ printf("\n\t\t\033[0;35mENTER TIME:[hh:mm]: \033[0m");
+ gets(time);
+
+ fp = fopen ( filename, "rb+" );
+
+ if ( fp == NULL )
+ {
+ printf("\n\t\t\t\t\033[0;31mRECORD DOES NOT EXISTS: ");
+ printf("\n\t\t\t\tPRESS ANY KEY TO GO BACK\033[0m");
+ getch();
+ return;
+ }
+
+ while ( fread ( &e, sizeof ( e ), 1, fp ) == 1 )
+ {
+ if(strcmp(e.time,time)==0)
+ {
+ printf("\033[0;36m\n\t\t\t\tYOUR OLD RECORD WAS AS:");
+ printf("\n\t\t\t\tTIME: %s",e.time);
+ printf("\n\t\t\t\tMEETING WITH: %s",e.name);
+ printf("\n\t\t\t\tMEETING AT: %s",e.place);
+ printf("\n\t\t\t\tDURATION: %s",e.duration);
+ printf("\n\t\t\t\tNOTE: %s",e.note);
+
+ printf("\033[0m\n\n\t\t\t\t\033[0;35mWHAT WOULD YOU LIKE TO EDIT..");
+ printf("\n\t\t\t\t[1] TIME.");
+ printf("\n\t\t\t\t[2] MEETING PERSON.");
+ printf("\n\t\t\t\t[3] MEETING PLACE.");
+ printf("\n\t\t\t\t[4] DURATION.");
+ printf("\n\t\t\t\t[5] NOTE.");
+ printf("\n\t\t\t\t[6] WHOLE RECORD.");
+ printf("\n\t\t\t\t[7] GO BACK TO MAIN MENU.");
+ do
+ {
+ printf("\n\n\t\t\t\tENTER YOUR CHOICE: \033[0m");
+ fflush(stdin);
+ scanf("%d",&num);
+ fflush(stdin);
+
+ switch(num)
+ {
+ case 1:
+ printf("\n\t\t\t\t\033[0;35mENTER THE NEW DATA: \033[0m");
+ printf("\n\t\t\t\t\033[0;35mNEW TIME:[hh:mm]: \033[0m");
+ gets(e.time);
+ break;
+
+ case 2:
+ printf("\n\t\t\t\t\033[0;35mENTER THE NEW DATA: \033[0m");
+ printf("\n\t\t\t\t\033[0;35mNEW MEETING PERSON: \033[0m");
+ gets(e.name);
+ break;
+
+ case 3:
+ printf("\n\t\t\t\t\033[0;35mENTER THE NEW DATA: \033[0m");
+ printf("\n\t\t\t\t\033[0;35mNEW MEETING PLACE: \033[0m");
+ gets(e.place);
+ break;
+
+ case 4:
+ printf("\n\t\t\t\t\033[0;35mENTER THE NEW DATA: \033[0m");
+ printf("\n\t\t\t\t\033[0;35mDURATION: \033[0m");
+ gets(e.duration);
+ break;
+
+ case 5:
+ printf("\n\t\t\t\t\033[0;35mENTER THE NEW DATA: \033[0m");
+ printf("\n\t\t\t\t\033[0;35mNOTE: \033[0m");
+ gets(e.note);
+ break;
+
+ case 6:
+ printf("\n\t\t\t\t\033[0;35mENTER THE NEW DATA: \033[0m");
+ printf("\n\t\t\t\t\033[0;35mNEW TIME:[hh:mm]: \033[0m");
+ gets(e.time);
+ printf("\n\t\t\t\t\033[0;35mNEW MEETING PERSON: \033[0m");
+ gets(e.name);
+ printf("\n\t\t\t\t\033[0;35mNEW MEETING PLACE: \033[0m");
+ gets(e.place);
+ printf("\n\t\t\t\t\033[0;35mDURATION: \033[0m");
+ gets(e.duration);
+ printf("\n\t\t\t\t\033[0;35mNOTE: \033[0m");
+ gets(e.note);
+ break;
+
+ case 7:
+ printf("\n\n\t\t\t\t\033[0;33mPRESS ANY KEY TO GO BACK...\033[0m\n");
+ getch();
+ return ;
+ break;
+
+ default:
+ printf("\n\n\t\t\t\t\033[0;31mYOU TYPED SOMETHING ELSE...TRY AGAIN\033[0m\n");
+ break;
+ }
+ }
+ while(num<1||num>8);
+ fseek(fp,-sizeof(e),SEEK_CUR);
+ fwrite(&e,sizeof(e),1,fp);
+ fseek(fp,-sizeof(e),SEEK_CUR);
+ fread(&e,sizeof(e),1,fp);
+ choice=5;
+ break;
+ }
+ }
+
+ if(choice==5)
+ {
+ system("cls");
+ printf("\n\t\t\t\t\033[0;32mEDITING COMPLETED...\n\n\n\033[0m");
+ printf("\033[0;36m-------------------------------------------------------------------------------------\n");
+ printf("\t\t\t\tTHE NEW RECORD IS:\n");
+ printf("-------------------------------------------------------------------------------------\n");
+ printf("\n\t\t\t\tTIME: %s",e.time);
+ printf("\n\t\t\t\tMEETING WITH: %s",e.name);
+ printf("\n\t\t\t\tMEETING AT: %s",e.place);
+ printf("\n\t\t\t\tDURATION: %s",e.duration);
+ printf("\n\t\t\t\tNOTE: %s",e.note);
+ fclose(fp);
+ printf("\033[0m\n\n\t\t\t\t\033[0m\033[0;35mWOULD YOU LIKE TO EDIT ANOTHER RECORD.(Y/N)\033[0m");
+ scanf("%c",&choice);
+ count++;
+ }
+ else
+ {
+ printf("\n\t\t\t\t\033[0;31mTHE RECORD DOES NOT EXIST::\n");
+ printf("\n\t\t\t\tWOULD YOU LIKE TO TRY AGAIN...(Y/N)\033[0m");
+ scanf("%c",&choice);
+ }
+ }
+ while(choice=='Y'||choice=='y');
+
+ fclose ( fp ) ;
+
+ if(count==1)
+ printf("\n\t\t\t\t\033[0;32m%d FILE IS EDITED...\n\n\n",count);
+ else if(count>1)
+ printf("\n\t\t\t\t%d FILES ARE EDITED..\n\n\n",count);
+ else
+ printf("\n\t\t\t\tNO FILES EDITED...\n\n\n");
+
+ printf("\t\t\t\t\033[0m\033[0;33mPRESS ANY KEY TO EXIT...\033[0m");
+ getch();
+}
+
+void changePassword(){
+ system("cls");
+ char ch, username[20], confirm[20]={0}, pass[15]={0};
+ FILE *fp;
+ int i,choice=0;
+ printf("\033[0;34m************************************************************************************\n");
+ printf("\t\t\t\tCHANGE PASSWORD\n");
+ printf("************************************************************************************\033[m\n");
+ printf("\n\n\t\033[0;31mPLEASE NOTE YOU HAVE TO ENTER PREVIOUS PASSWORD TO ADD NEW PASSWORD\n\t ENTER YOUR PASSWORD CAREFULLY. YOU HAVE ONLY THREE CHANCES.\033[0m\n");
+ printf("\n\n\t\t\t\033[0;33mPress Any Key To Continue...\n\033[0m");
+ getch();
+
+ int access=login();
+ system("cls");
+ if(access){
+ do{
+ printf("\033[0;34m************************************************************************************\n");
+ printf("\t\t\t\tCHANGE PASSWORD\n");
+ printf("************************************************************************************\033[m\n");
+ fp = fopen("login.txt","w"); //OPENS IN WRITE MODE AND CLEARS ALL PRESENT DATA
+ if(fp==NULL){
+ printf("\n\033[0;31mError with the login file...[MISSING]\033[0m\n");
+ getch();
+ return;
+ }
+ else{
+ i=0;
+ printf("\t\t\033[0;35mENTER THE NEW PASSWORD : \033[0m");
+ do{
+ pass[i]=getch();
+ if(pass[i]!='\r')
+ printf("*");
+ i++;
+ }while(pass[i-1]!='\r');
+ pass[i-1]='\0';
+
+ i=0;
+ printf("\n\n\t\t\033[0;35mENTER THE CONFIRM PASSWORD : \033[0m");
+ do{
+ confirm[i]=getch();
+ if(confirm[i]!='\r')
+ printf("*");
+ i++;
+ }while(confirm[i-1]!='\r');
+ confirm[i-1]='\0';
+
+ if(strcmp(pass,confirm)==0){
+ i=0;
+ while(pass[i]!='\0'){
+ ch=pass[i];
+ putc(ch,fp); //INSERTS INTO THE FILE
+ i++;
+ }
+
+ putc(EOF,fp);
+
+ fclose(fp);
+ choice=0;
+ }
+ else{
+ printf("\n\n\t\t\033[0;31mTHE NEW PASSWORD DOES NOT MATCH\033[0m\n\n");
+ printf("\t\tPress Any Key...\n");
+ getch();
+ choice=1;
+ system("cls");
+ }
+ }
+ }while(choice);
+ printf("\n\n\t\t\t\t\033[0;32mPASSWORD CHANGED SUCCESSFULLY...\033[0m\n\n\t\t\t\t\033[0;33mPRESS ANY KEY TO GO BACK...\033[0m\n\n\n");
+ getch();
+ }
+}
diff --git a/C/Diary Management/login.txt b/C/Diary Management/login.txt
new file mode 100644
index 000000000..72c2c97c3
--- /dev/null
+++ b/C/Diary Management/login.txt
@@ -0,0 +1 @@
+abcdeÿ
\ No newline at end of file
diff --git a/C/Fibonacci Triangle.c b/C/Fibonacci Triangle.c
new file mode 100644
index 000000000..2c02f41ea
--- /dev/null
+++ b/C/Fibonacci Triangle.c
@@ -0,0 +1,24 @@
+#include
+#include
+int main(){
+ int a=0,b=1,i,c,n,j;
+system("cls");
+ printf("Enter the limit:");
+ scanf("%d",&n);
+ for(i=1;i<=n;i++)
+ {
+ a=0;
+ b=1;
+ printf("%d\t",b);
+ for(j=1;j
+#include
+
+#define MAX_DEGREE 5
+#define MAX_NUM_VERTICES 20
+
+struct vertices_s {
+ int visited;
+ int deg;
+ int adj[MAX_DEGREE]; /* < 0 if incoming edge */
+} vertices[] = {
+ {0, 3, {2, -3, 4}},
+ {0, 2, {-1, 3}},
+ {0, 3, {1, -2, 7}},
+ {0, 3, {-1, -5, 6}},
+ {0, 2, {4, -7}},
+ {0, 3, {-4, 7, -8}},
+ {0, 4, {-3, 5, -6, -12}},
+ {0, 3, {6, -9, 11}},
+ {0, 2, {8, -10}},
+ {0, 3, {9, -11, -12}},
+ {0, 3, {-8, 10, 12}},
+ {0, 3, {7, 10, -11}}
+};
+int num_vertices = sizeof(vertices) / sizeof(vertices[0]);
+
+struct stack_s {
+ int top;
+ int items[MAX_NUM_VERTICES];
+} stack = {-1, {}};
+
+void stack_push(int v) {
+ stack.top++;
+ if (stack.top < MAX_NUM_VERTICES)
+ stack.items[stack.top] = v;
+ else {
+ printf("Stack is full!\n");
+ exit(1);
+ }
+}
+
+int stack_pop() {
+ return stack.top < 0 ? -1 : stack.items[stack.top--];
+}
+
+void dfs(int v, int transpose) {
+ int i, c, n;
+ vertices[v].visited = 1;
+ for (i = 0, c = vertices[v].deg; i < c; ++i) {
+ n = vertices[v].adj[i] * transpose;
+ if (n > 0)
+ /* n - 1 because vertex indexing begins at 0 */
+ if (!vertices[n - 1].visited)
+ dfs(n - 1, transpose);
+ }
+ if (transpose < 0)
+ stack_push(v);
+ else
+ printf("%d ", v + 1);
+}
+
+void reset_visited() {
+ int i;
+ for (i = 0; i < num_vertices; ++i)
+ vertices[i].visited = 0;
+}
+
+void order_pass() {
+ int i;
+ for (i = 0; i < num_vertices; ++i)
+ if (!vertices[i].visited)
+ dfs(i, -1);
+}
+
+void scc_pass() {
+ int i = 0, v;
+ while((v = stack_pop()) != -1) {
+ if (!vertices[v].visited) {
+ printf("scc %d: ", ++i);
+ dfs(v, 1);
+ printf("\n");
+ }
+ }
+}
+
+int main(void) {
+ order_pass();
+ reset_visited();
+ scc_pass();
+ return 0;
+}
\ No newline at end of file
diff --git a/C/LibManagement b/C/LibManagement
new file mode 100644
index 000000000..720fe110c
--- /dev/null
+++ b/C/LibManagement
@@ -0,0 +1,76 @@
+#include
+#include
+#include
+
+struct library
+{
+ char bk_name[30];
+ char author[30];
+ int pages;
+ float price;
+};
+int main()
+{
+ struct library l[100];
+ char ar_nm[30],bk_nm[30];
+ int i,j, keepcount;
+ i=j=keepcount = 0;
+ while(j!=6)
+ {
+ printf("\n\n1. Add book information\n2. Display book information\n");
+ printf("3. List all books of given author\n");
+ printf("4. List the title of specified book\n");
+ printf("5. List the count of books in the library\n");
+ printf("6. Exit");
+ printf ("\n\nEnter one of the above : ");
+ scanf("%d",&j);
+ switch (j)
+ {
+ case 1:
+ printf ("Enter book name = ");
+ scanf ("%s",l[i].bk_name);
+ printf ("Enter author name = ");
+ scanf ("%s",l[i].author);
+ printf ("Enter pages = ");
+ scanf ("%d",&l[i].pages);
+ printf ("Enter price = ");
+ scanf ("%f",&l[i].price);
+ keepcount++;
+ break;
+ case 2:
+ printf("you have entered the following information\n");
+ for(i=0; i
+#include
+void main()
+{
+clrscr();
+int i,n,a[100],search;
+printf("Enter number of elements : ");
+scanf("%d",&n);
+printf("\nEnter %d elements : \n",n);
+for(i=0;i
+
+int search(int arr[], int n, int x)
+{
+ int i;
+ for (i = 0; i < n; i++)
+ if (arr[i] == x)
+ return i;
+ return -1;
+}
+
+int main(void)
+{
+ int arr[] = { 2, 36, 4, 15, 40 };
+ int x = 4;
+ int n = sizeof(arr) / sizeof(arr[0]);
+
+ // Function call
+ int result = search(arr, n, x);
+ (result == -1)
+ ? printf("Element is not present in array")
+ : printf("Element is present at index %d", result);
+ return 0;
+}
diff --git a/C/LruPageReplacement.c b/C/LruPageReplacement.c
new file mode 100644
index 000000000..6e252510d
--- /dev/null
+++ b/C/LruPageReplacement.c
@@ -0,0 +1,86 @@
+#include
+int n,nf,in[100],p[50];
+int hit=0,i,j,k;
+int pgfaultcnt=0;
+
+void getData(){
+ printf("\nEnter length of page reference sequence:");
+ scanf("%d",&n);
+ printf("\nEnter the page reference sequence:");
+ for(i=0; i=0; k--){
+ if(pg==in[k]){
+ least[j]=k;
+ found=1;
+ break;
+ }
+ else
+ found=0;
+ }
+ if(!found)
+ least[j]=-9999;
+ }
+ int min=9999;
+ int repindex;
+ for(j=0; j
+#include
+
+bool isPalindrome(int a)
+{
+ int backup = a,rev = 0;
+
+ while(a)
+ {
+ rev = (rev*10) + (a%10);
+ a/=10;
+ }
+
+ return rev == backup;
+}
+
+int main()
+{
+ int n = 122;
+
+ if(isPalindrome(n))
+ printf("%d is a Palindrome Number",n);
+ else
+ printf("%d is not a Palindrome Number",n);
+
+ return 0;
+
+}
diff --git a/C/Snake_game.c b/C/Snake_game.c
new file mode 100644
index 000000000..5998caaae
--- /dev/null
+++ b/C/Snake_game.c
@@ -0,0 +1,184 @@
+#include
+#include
+#include
+#include
+#include
+#include
+
+check();
+end();
+win();
+int m[500],n[500],con=20;
+clock_t start,stop;
+ void main(void)
+{
+
+int gd=DETECT,gm,ch,maxx,maxy,x=13,y=14,p,q,spd=100;
+
+initgraph(&gd,&gm,"..\bgi");
+
+setcolor(WHITE);
+settextstyle(3,0,6);
+outtextxy(200,2," SNAKE 2 ");
+settextstyle(6,0,2);
+outtextxy(20,80," Use Arrow Keys To Direct The Snake ");
+outtextxy(20,140," Avoid The Head Of Snake Not To Hit Any Part Of Snake
+");
+outtextxy(20,160," Pick The Beats Untill You Win The Game ");
+outtextxy(20,200," Press 'Esc' Anytime To Exit ");
+outtextxy(20,220," Press Any Key To Continue ");
+ch=getch();
+if(ch==27) exit(0);
+cleardevice();
+maxx=getmaxx();
+maxy=getmaxy();
+
+randomize();
+
+p=random(maxx);
+int temp=p%13;
+p=p-temp;
+q=random(maxy);
+temp=q%14;
+q=q-temp;
+
+
+
+ start=clock();
+int a=0,i=0,j,t;
+while(1)
+{
+
+ setcolor(WHITE);
+ setfillstyle(SOLID_FILL,con+5);
+ circle(p,q,5);
+ floodfill(p,q,WHITE);
+
+ if( kbhit() )
+ {
+ ch=getch(); if(ch==0) ch=getch();
+ if(ch==72&& a!=2) a=1;
+ if(ch==80&& a!=1) a=2;
+ if(ch==75&& a!=4) a=3;
+ if(ch==77&& a!=3) a=4;
+ }
+ else
+ {
+ if(ch==27
+ ) break;
+ }
+
+ if(i<20){
+ m[i]=x;
+ n[i]=y;
+ i++;
+ }
+
+ if(i>=20)
+
+ {
+ for(j=con;j>=0;j--){
+ m[1+j]=m[j];
+ n[1+j]=n[j];
+ }
+ m[0]=x;
+ n[0]=y;
+
+ setcolor(WHITE);
+ setfillstyle(SOLID_FILL,con);
+ circle(m[0],n[0],8);
+ floodfill(m[0],n[0],WHITE);
+
+ setcolor(WHITE);
+ for(j=1;j=5) spd=spd-5; else spd=5;
+ if(con>490) win();
+ p=random(maxx); temp=p%13; p=p-temp;
+ q=random(maxy); temp=q%14; q=q-temp;
+ }
+ if(a==1) y = y-14; if(y<0) { temp=maxy%14;y=maxy-temp;}
+ if(a==2) y = y+14; if(y>maxy) y=0;
+ if(a==3) x = x-13; if(x<0) { temp=maxx%13;x=maxx-temp;}
+ if(a==4) x = x+13; if(x>maxx) x=0;
+ if(a==0){ y = y+14 ; x=x+13; }
+ }
+
+ }
+
+
+check(){
+ int a;
+ for(a=1;a
+
+ int main(){
+ int a;
+ int i=0;
+ int c=0;
+ printf("enter the value of no till which required to be added\n");
+ scanf("%d",&a);
+ while (i<(a+1)){
+ c=(c+i);
+ i++;
+ }
+ printf("result is %d",c);
+ return 0;
+ }
+
diff --git a/C/bubble_sort.c b/C/bubble_sort.c
new file mode 100644
index 000000000..2e0464604
--- /dev/null
+++ b/C/bubble_sort.c
@@ -0,0 +1,24 @@
+#include
+int main()
+{
+ int n, temp, i, j;
+ printf ("Enter No of elements in the array \n");
+ scanf("%d",&n);
+ int number[n];
+ printf ("Enter the elements of array \n");
+ for(int i=0;i=0;i--){
+ for(j=0;j<=i;j++){
+ if(number[j]>number[j+1]){
+ temp=number[j];
+ number[j]=number[j+1];
+ number[j+1]=temp;
+ }
+ }
+ }
+ printf("Sorted elements: ");
+ for(i=0;i
+#include
+int change(int n);
+int main()
+{
+ int n;
+ printf("Enter a number in decimal : ");
+ scanf("%d",&n);
+ int m = change(n);
+ printf ("The number %d in binary is %d",n,m);
+}
+int change(int n)
+{
+ int dec=0,i=1,rem;
+ while(n!=0)
+ {
+ rem = n % 2;
+ n /= 2;
+ dec += rem * i;
+ i *= 10;
+ }
+ return dec;
+}
\ No newline at end of file
diff --git a/C/factorial.c b/C/factorial.c
new file mode 100644
index 000000000..00b2dd76f
--- /dev/null
+++ b/C/factorial.c
@@ -0,0 +1,13 @@
+#include
+int main()
+{
+ int i,fact=1,number;
+ printf("Enter a number: ");
+ scanf("%d",&number);
+ for(i=1;i<=number;i++)
+ {
+ fact=fact*i;
+ }
+ printf("Factorial of %d is: %d",number,fact);
+return 0;
+}
\ No newline at end of file
diff --git a/C/filter/filter.c b/C/filter/filter.c
new file mode 100644
index 000000000..e0e796e14
--- /dev/null
+++ b/C/filter/filter.c
@@ -0,0 +1,153 @@
+#include
+#include
+#include
+
+#include "helpers.h"
+
+int main(int argc, char *argv[])
+{
+
+ // Define allowable filters
+ char *filters = "bgrs";
+
+ // Get filter flag and check validity
+ char filter = getopt(argc, argv, filters);
+ if (filter == '?')
+ {
+ fprintf(stderr, "Invalid filter.\n");
+ return 1;
+ }
+
+ // Ensure only one filter
+ if (getopt(argc, argv, filters) != -1)
+ {
+ fprintf(stderr, "Only one filter allowed.\n");
+ return 2;
+ }
+
+ // Ensure proper usage
+ if (argc != optind + 2)
+ {
+ fprintf(stderr, "Usage: filter [flag] infile outfile\n");
+ return 3;
+ }
+
+ // Remember filenames
+ char *infile = argv[optind];
+ char *outfile = argv[optind + 1];
+
+ // Open input file
+ FILE *inptr = fopen(infile, "r");
+ if (inptr == NULL)
+ {
+ fprintf(stderr, "Could not open %s.\n", infile);
+ return 4;
+ }
+
+ // Open output file
+ FILE *outptr = fopen(outfile, "w");
+ if (outptr == NULL)
+ {
+ fclose(inptr);
+ fprintf(stderr, "Could not create %s.\n", outfile);
+ return 5;
+ }
+
+ // Read infile's BITMAPFILEHEADER
+ BITMAPFILEHEADER bf;
+ fread(&bf, sizeof(BITMAPFILEHEADER), 1, inptr);
+
+ // Read infile's BITMAPINFOHEADER
+ BITMAPINFOHEADER bi;
+ fread(&bi, sizeof(BITMAPINFOHEADER), 1, inptr);
+
+ // Ensure infile is (likely) a 24-bit uncompressed BMP 4.0
+ if (bf.bfType != 0x4d42 || bf.bfOffBits != 54 || bi.biSize != 40 ||
+ bi.biBitCount != 24 || bi.biCompression != 0)
+ {
+ fclose(outptr);
+ fclose(inptr);
+ fprintf(stderr, "Unsupported file format.\n");
+ return 6;
+ }
+
+ int height = abs(bi.biHeight);
+ int width = bi.biWidth;
+
+ // Allocate memory for image
+ RGBTRIPLE(*image)[width] = calloc(height, width * sizeof(RGBTRIPLE));
+ if (image == NULL)
+ {
+ fprintf(stderr, "Not enough memory to store image.\n");
+ fclose(outptr);
+ fclose(inptr);
+ return 7;
+ }
+
+ // Determine padding for scanlines
+ int padding = (4 - (width * sizeof(RGBTRIPLE)) % 4) % 4;
+
+ // Iterate over infile's scanlines
+ for (int i = 0; i < height; i++)
+ {
+ // Read row into pixel array
+ fread(image[i], sizeof(RGBTRIPLE), width, inptr);
+
+ // Skip over padding
+ fseek(inptr, padding, SEEK_CUR);
+ }
+
+ // Filter image
+ switch (filter)
+ {
+ // Blur
+ case 'b':
+ blur(height, width, image);
+ break;
+
+ // Grayscale
+ case 'g':
+ grayscale(height, width, image);
+ break;
+
+ // Reflection
+ case 'r':
+ reflect(height, width, image);
+ break;
+
+ // Sepia
+ case 's':
+ sepia(height, width, image);
+ break;
+ }
+
+ // Write outfile's BITMAPFILEHEADER
+ fwrite(&bf, sizeof(BITMAPFILEHEADER), 1, outptr);
+
+ // Write outfile's BITMAPINFOHEADER
+ fwrite(&bi, sizeof(BITMAPINFOHEADER), 1, outptr);
+
+ // Write new pixels to outfile
+ for (int i = 0; i < height; i++)
+ {
+ // Write row to outfile
+ fwrite(image[i], sizeof(RGBTRIPLE), width, outptr);
+
+ // Write padding at end of row
+ for (int k = 0; k < padding; k++)
+ {
+ fputc(0x00, outptr);
+ }
+ }
+
+ // Free memory for image
+ free(image);
+
+ // Close infile
+ fclose(inptr);
+
+ // Close outfile
+ fclose(outptr);
+
+ return 0;
+}
diff --git a/C/filter/helpers.c b/C/filter/helpers.c
new file mode 100644
index 000000000..c857c8780
--- /dev/null
+++ b/C/filter/helpers.c
@@ -0,0 +1,192 @@
+#include "helpers.h"
+#include
+
+// Convert image to grayscale
+void grayscale(int height, int width, RGBTRIPLE image[height][width])
+{
+ for (int i = 0; i < height; i++)
+ {
+ for (int j = 0; j < width; j++)
+ {
+ // calculating average of RGB for a pixel
+ int a = round((image[i][j].rgbtBlue + image[i][j].rgbtGreen + image[i][j].rgbtRed) / 3.0);
+ image[i][j].rgbtBlue = a;
+ image[i][j].rgbtGreen = a;
+ image[i][j].rgbtRed = a;
+ }
+ }
+ return;
+}
+
+// Convert image to sepia
+void sepia(int height, int width, RGBTRIPLE image[height][width])
+{
+ for (int i = 0; i < height; i++)
+ {
+ for (int j = 0; j < width; j++)
+ {
+ int a, b, c;
+ a = round(0.272 * image[i][j].rgbtRed + 0.534 * image[i][j].rgbtGreen + 0.131 * image[i][j].rgbtBlue);
+ b = round(0.349 * image[i][j].rgbtRed + 0.686 * image[i][j].rgbtGreen + 0.168 * image[i][j].rgbtBlue);
+ c = round(0.393 * image[i][j].rgbtRed + 0.769 * image[i][j].rgbtGreen + 0.189 * image[i][j].rgbtBlue);
+ // if statements have been used to prevent integer overflow
+ if (a > 255)
+ {
+ image[i][j].rgbtBlue = 255;
+ }
+ else
+ {
+ image[i][j].rgbtBlue = a;
+ }
+ if (b > 255)
+ {
+ image[i][j].rgbtGreen = 255;
+ }
+ else
+ {
+ image[i][j].rgbtGreen = b;
+ }
+ if (c > 255)
+ {
+ image[i][j].rgbtRed = 255;
+ }
+ else
+ {
+ image[i][j].rgbtRed = c;
+ }
+ }
+ }
+ return;
+}
+
+// Reflect image horizontally
+void reflect(int height, int width, RGBTRIPLE image[height][width])
+{
+ RGBTRIPLE temp;
+ // replacing pixels on RHS to LHS and vice versa
+ for (int i = 0; i < height; i++)
+ {
+ for (int j = 0; j < width / 2; j++)
+ {
+ temp = image[i][j];
+ image[i][j] = image[i][width - 1 - j];
+ image[i][width - 1 - j] = temp;
+ }
+ }
+ return;
+}
+
+// Blur image
+void blur(int height, int width, RGBTRIPLE image[height][width])
+{
+ // declaring and initialising temporarary variables to 0 to store pixels' new data
+ unsigned long long int sum1[height][width], sum2[height][width], sum3[height][width];
+ for (int i = 0; i < height; i++)
+ {
+ for (int j = 0; j < width; j++)
+ {
+ sum1[i][j] = 0;
+ sum2[i][j] = 0;
+ sum3[i][j] = 0;
+ }
+ }
+
+ // for those pixels which are surrounded by 8 pixels
+ for (int i = 1; i < height - 1; i++)
+ {
+ for (int j = 1; j < width - 1; j++)
+ {
+ for (int k = i - 1; k < i + 2; k++)
+ {
+ for (int l = j - 1; l < j + 2; l++)
+ {
+ {
+ sum1[i][j] += image[k][l].rgbtRed;
+ sum2[i][j] += image[k][l].rgbtGreen;
+ sum3[i][j] += image[k][l].rgbtBlue;
+ }
+ }
+ }
+ sum1[i][j] = round(sum1[i][j] / 9.0);
+ sum2[i][j] = round(sum2[i][j] / 9.0);
+ sum3[i][j] = round(sum3[i][j] / 9.0);
+ }
+ }
+
+ // for pixels on corners
+
+ // don't attempt to understand following module.you can't. It's a mess which took hell a lot of time to write
+ int array1[4][4] = {{0, 1, 1, 0}, {0, 1, 1, 0}, {height - 1, height - 2, height - 2, height - 1}, {height - 1, height - 2, height - 2, height - 1}};
+ int array2[4][4] = {{1, 0, 1, 0}, {width - 2, width - 1, width - 2, width - 1}, {width - 2, width - 1, width - 2, width - 1}, {1, 0, 1, 0}};
+ for (int i = 0; i < 4; i++)
+ {
+ for (int j = 0; j < 4; j++)
+ {
+ sum1[array1[i][0]][array2[i][1]] += image[array1[i][j]][array2[i][j]].rgbtRed;
+ sum2[array1[i][0]][array2[i][1]] += image[array1[i][j]][array2[i][j]].rgbtGreen;
+ sum3[array1[i][0]][array2[i][1]] += image[array1[i][j]][array2[i][j]].rgbtBlue;
+ }
+ sum1[array1[i][0]][array2[i][1]] = round((sum1[array1[i][0]][array2[i][1]]) / 4.0);
+ sum2[array1[i][0]][array2[i][1]] = round((sum2[array1[i][0]][array2[i][1]]) / 4.0);
+ sum3[array1[i][0]][array2[i][1]] = round((sum3[array1[i][0]][array2[i][1]]) / 4.0);
+ }
+ // for pixels on the edges
+
+ //(for edges on vertical sides)
+ for (int i = 1; i < height - 1; i++)
+ {
+ for (int j = 0; j < 2; j++)
+ {
+ sum1[i][0] += image[i][j].rgbtRed + image[i - 1][j].rgbtRed + image[i + 1][j].rgbtRed;
+ sum2[i][0] += image[i][j].rgbtGreen + image[i - 1][j].rgbtGreen + image[i + 1][j].rgbtGreen;
+ sum3[i][0] += image[i][j].rgbtBlue + image[i - 1][j].rgbtBlue + image[i + 1][j].rgbtBlue;
+ }
+ sum1[i][0] = round((sum1[i][0]) / 6.0);
+ sum2[i][0] = round((sum2[i][0]) / 6.0);
+ sum3[i][0] = round((sum3[i][0]) / 6.0);
+ for (int j = width - 2; j < width; j++)
+ {
+ sum1[i][height - 1] += image[i][j].rgbtRed + image[i - 1][j].rgbtRed + image[i + 1][j].rgbtRed;
+ sum2[i][height - 1] += image[i][j].rgbtGreen + image[i - 1][j].rgbtGreen + image[i + 1][j].rgbtGreen;
+ sum3[i][height - 1] += image[i][j].rgbtBlue + image[i - 1][j].rgbtBlue + image[i + 1][j].rgbtBlue;
+ }
+ sum1[i][height - 1] = round(sum1[i][height - 1] / 6.0);
+ sum2[i][height - 1] = round(sum2[i][height - 1] / 6.0);
+ sum3[i][height - 1] = round(sum3[i][height - 1] / 6.0);
+ }
+
+ //(for edges on horizontal sides)
+ for (int j = 1; j < width - 1; j++)
+ {
+ for (int i = 0; i < 2; i++)
+ {
+ sum1[0][j] += image[i][j - 1].rgbtRed + image[i][j].rgbtRed + image[i][j + 1].rgbtRed;
+ sum2[0][j] += image[i][j - 1].rgbtGreen + image[i][j].rgbtGreen + image[i][j + 1].rgbtGreen;
+ sum3[0][j] += image[i][j - 1].rgbtBlue + image[i][j].rgbtBlue + image[i][j + 1].rgbtBlue;
+ }
+ sum1[0][j] = round(sum1[0][j] / 6.0);
+ sum2[0][j] = round(sum2[0][j] / 6.0);
+ sum3[0][j] = round(sum3[0][j] / 6.0);
+ for (int i = height - 2; i < height; i++)
+ {
+ sum1[height - 1][j] += image[i][j - 1].rgbtRed + image[i][j].rgbtRed + image[i][j + 1].rgbtRed;
+ sum2[height - 1][j] += image[i][j - 1].rgbtGreen + image[i][j].rgbtGreen + image[i][j + 1].rgbtGreen;
+ sum3[height - 1][j] += image[i][j - 1].rgbtBlue + image[i][j].rgbtBlue + image[i][j + 1].rgbtBlue;
+ }
+ sum1[height - 1][j] = round(sum1[height - 1][j] / 6.0);
+ sum2[height - 1][j] = round(sum2[height - 1][j] / 6.0);
+ sum3[height - 1][j] = round(sum3[height - 1][j] / 6.0);
+ }
+
+ // copying pixels' new data from temporary variables to images[i][j]
+ for (int i = 0; i < height; i++)
+ {
+ for (int j = 0; j < width; j++)
+ {
+ image[i][j].rgbtRed = sum1[i][j];
+ image[i][j].rgbtGreen = sum2[i][j];
+ image[i][j].rgbtBlue = sum3[i][j];
+ }
+ }
+ return;
+}
diff --git a/C/filter/helpers.h b/C/filter/helpers.h
new file mode 100644
index 000000000..412da8cfc
--- /dev/null
+++ b/C/filter/helpers.h
@@ -0,0 +1,13 @@
+#include "bmp.h"
+
+// Convert image to grayscale
+void grayscale(int height, int width, RGBTRIPLE image[height][width]);
+
+// Convert image to sepia
+void sepia(int height, int width, RGBTRIPLE image[height][width]);
+
+// Reflect image horizontally
+void reflect(int height, int width, RGBTRIPLE image[height][width]);
+
+// Blur image
+void blur(int height, int width, RGBTRIPLE image[height][width]);
diff --git a/C/filter/makefile.txt b/C/filter/makefile.txt
new file mode 100644
index 000000000..73a0f660d
--- /dev/null
+++ b/C/filter/makefile.txt
@@ -0,0 +1,2 @@
+filter:
+ clang -ggdb3 -O0 -Qunused-arguments -std=c11 -Wall -Werror -Wextra -Wno-sign-compare -Wno-unused-parameter -Wno-unused-variable -Wshadow -lm -o filter filter.c helpers.c
diff --git a/C/infix_to_prefix.c b/C/infix_to_prefix.c
new file mode 100644
index 000000000..c83f38c05
--- /dev/null
+++ b/C/infix_to_prefix.c
@@ -0,0 +1,117 @@
+ /* infix to prefix conversion*/
+
+#include
+#include
+#define MAX 20
+char stack[MAX];
+int top=-1;
+void push(char item)
+{
+ top++;
+ stack[top]=item;
+}
+char pop()
+{
+ char a;
+ a=stack[top];
+ top--;
+ return a;
+}
+int prcd(char symbol)
+{
+ switch(symbol)
+ {
+ case '+':
+ case '-': return 2;
+ case '*':
+ case '/': return 4;
+ case '^':
+ case '$': return 6;
+ case '(':
+ case ')':
+ case '#': return 1;
+ }
+ return 0;
+}
+int isoperator(char symbol)
+{
+ switch(symbol)
+ {
+ case '+':
+ case '-':
+ case '*':
+ case '/':
+ case '^':
+ case '$':
+ case '(':
+ case ')': return 1;
+ default: return 0;
+ }
+}
+void infix_to_prefix(char infix[], char prefix[])
+{
+ int i,symbol,j=0;
+ char test[MAX];
+ infix=strrev(infix);
+ stack[++top]='#';
+ for(i=0;i=prcd(stack[top])))
+ {
+ push(symbol);
+ }
+ else
+ {
+ while(prcd(symbol)
+
+int main()
+{
+ int arr[50];
+ int n, number, ind = -1;
+ printf("Enter the number of elements : ");
+ scanf("%d", &n);
+ printf("Enter Array Elements : ");
+ for (int i = 0; i < n; i++)
+ {
+ scanf("%d", &arr[i]);
+ }
+ printf("\nEnter the Number to be searched : ");
+ scanf("%d", &number);
+ for (int i = 0; i < n; i++)
+ {
+ if (number == arr[i])
+ {
+ ind = i;
+ break;
+ }
+ }
+ if (ind != -1)
+ {
+ printf("\nElement %d found at %d position", number, ind + 1);
+ }
+ else
+ {
+ printf("Element not found :)\n");
+ }
+ return 0;
+}
\ No newline at end of file
diff --git a/C/linked_list.c b/C/linked_list.c
new file mode 100644
index 000000000..a395deebb
--- /dev/null
+++ b/C/linked_list.c
@@ -0,0 +1,263 @@
+// Singly LinkedList with all operaions in C language
+
+#include
+#include
+struct node
+{
+ int data;
+ struct node *next;
+};
+struct node *head;
+
+void beginsert();
+void lastinsert();
+void randominsert();
+void begin_delete();
+void last_delete();
+void random_delete();
+void display();
+void search();
+void main()
+{
+ int choice = 0;
+ while (choice != 9)
+ {
+ printf("\n\n*********Main Menu*********\n");
+ printf("\nChoose one option from the following list ...\n");
+ printf("\n===============================================\n");
+ printf("\n1.Insert in begining\n2.Insert at last\n3.Insert at any random location\n4.Delete from Beginning\n5.Delete from last\n6.Delete node after specified location\n7.Search for an element\n8.Show\n9.Exit\n");
+ printf("\nEnter your choice?\n");
+ scanf("\n%d", &choice);
+ switch (choice)
+ {
+ case 1:
+ beginsert();
+ break;
+ case 2:
+ lastinsert();
+ break;
+ case 3:
+ randominsert();
+ break;
+ case 4:
+ begin_delete();
+ break;
+ case 5:
+ last_delete();
+ break;
+ case 6:
+ random_delete();
+ break;
+ case 7:
+ search();
+ break;
+ case 8:
+ display();
+ break;
+ case 9:
+ exit(0);
+ break;
+ default:
+ printf("Please enter valid choice..");
+ }
+ }
+}
+void beginsert()
+{
+ struct node *ptr;
+ int item;
+ ptr = (struct node *)malloc(sizeof(struct node *));
+ if (ptr == NULL)
+ {
+ printf("\nOVERFLOW");
+ }
+ else
+ {
+ printf("\nEnter value\n");
+ scanf("%d", &item);
+ ptr->data = item;
+ ptr->next = head;
+ head = ptr;
+ printf("\nNode inserted");
+ }
+}
+void lastinsert()
+{
+ struct node *ptr, *temp;
+ int item;
+ ptr = (struct node *)malloc(sizeof(struct node));
+ if (ptr == NULL)
+ {
+ printf("\nOVERFLOW");
+ }
+ else
+ {
+ printf("\nEnter value?\n");
+ scanf("%d", &item);
+ ptr->data = item;
+ if (head == NULL)
+ {
+ ptr->next = NULL;
+ head = ptr;
+ printf("\nNode inserted");
+ }
+ else
+ {
+ temp = head;
+ while (temp->next != NULL)
+ {
+ temp = temp->next;
+ }
+ temp->next = ptr;
+ ptr->next = NULL;
+ printf("\nNode inserted");
+ }
+ }
+}
+void randominsert()
+{
+ int i, loc, item;
+ struct node *ptr, *temp;
+ ptr = (struct node *)malloc(sizeof(struct node));
+ if (ptr == NULL)
+ {
+ printf("\nOVERFLOW");
+ }
+ else
+ {
+ printf("\nEnter element value");
+ scanf("%d", &item);
+ ptr->data = item;
+ printf("\nEnter the location after which you want to insert ");
+ scanf("\n%d", &loc);
+ temp = head;
+ for (i = 0; i < loc; i++)
+ {
+ temp = temp->next;
+ if (temp == NULL)
+ {
+ printf("\ncan't insert\n");
+ return;
+ }
+ }
+ ptr->next = temp->next;
+ temp->next = ptr;
+ printf("\nNode inserted");
+ }
+}
+void begin_delete()
+{
+ struct node *ptr;
+ if (head == NULL)
+ {
+ printf("\nList is empty\n");
+ }
+ else
+ {
+ ptr = head;
+ head = ptr->next;
+ free(ptr);
+ printf("\nNode deleted from the begining ...\n");
+ }
+}
+void last_delete()
+{
+ struct node *ptr, *ptr1;
+ if (head == NULL)
+ {
+ printf("\nlist is empty");
+ }
+ else if (head->next == NULL)
+ {
+ head = NULL;
+ free(head);
+ printf("\nOnly node of the list deleted ...\n");
+ }
+
+ else
+ {
+ ptr = head;
+ while (ptr->next != NULL)
+ {
+ ptr1 = ptr;
+ ptr = ptr->next;
+ }
+ ptr1->next = NULL;
+ free(ptr);
+ printf("\nDeleted Node from the last ...\n");
+ }
+}
+void random_delete()
+{
+ struct node *ptr, *ptr1;
+ int loc, i;
+ printf("\n Enter the location of the node after which you want to perform deletion \n");
+ scanf("%d", &loc);
+ ptr = head;
+ for (i = 0; i < loc; i++)
+ {
+ ptr1 = ptr;
+ ptr = ptr->next;
+
+ if (ptr == NULL)
+ {
+ printf("\nCan't delete");
+ return;
+ }
+ }
+ ptr1->next = ptr->next;
+ free(ptr);
+ printf("\nDeleted node %d ", loc + 1);
+}
+void search()
+{
+ struct node *ptr;
+ int item, i = 0, flag;
+ ptr = head;
+ if (ptr == NULL)
+ {
+ printf("\nEmpty List\n");
+ }
+ else
+ {
+ printf("\nEnter item which you want to search?\n");
+ scanf("%d", &item);
+ while (ptr != NULL)
+ {
+ if (ptr->data == item)
+ {
+ printf("item found at location %d ", i + 1);
+ flag = 0;
+ }
+ else
+ {
+ flag = 1;
+ }
+ i++;
+ ptr = ptr->next;
+ }
+ if (flag == 1)
+ {
+ printf("Item not found\n");
+ }
+ }
+}
+
+void display()
+{
+ struct node *ptr;
+ ptr = head;
+ if (ptr == NULL)
+ {
+ printf("Nothing to print");
+ }
+ else
+ {
+ printf("\nprinting values . . . . .\n");
+ while (ptr != NULL)
+ {
+ printf("\n%d", ptr->data);
+ ptr = ptr->next;
+ }
+ }
+}
\ No newline at end of file
diff --git a/C/longest_common_subsequence.c b/C/longest_common_subsequence.c
new file mode 100644
index 000000000..1ae2d99dc
--- /dev/null
+++ b/C/longest_common_subsequence.c
@@ -0,0 +1,57 @@
+#include
+#include
+#include
+#include
+
+int max(int a, int b)
+{
+ if(a>b)
+ return a;
+ else
+ return b;
+}
+
+int main() {
+
+ int a[101], b[101], k, res[101];
+ int lcs[102][102] = {0};
+ int n,m, i, j;
+ scanf("%d %d", &n, &m);
+ for(i=0; i lcs[i][j-1])
+ --i;
+ else
+ --j;
+ }
+ }
+
+ for(i=0; i
+
+int main() {
+ int a, b, c, i, n;
+
+ n = 4;
+
+ a = b = 1;
+
+ printf("%d %d ",a,b);
+
+ for(i = 1; i <= n-2; i++) {
+ c = a + b;
+ printf("%d ", c);
+
+ a = b;
+ b = c;
+ }
+
+ return 0;
+}
diff --git a/C/max_min.c b/C/max_min.c
new file mode 100644
index 000000000..cd9ba2c58
--- /dev/null
+++ b/C/max_min.c
@@ -0,0 +1,28 @@
+#include
+int main()
+{
+ int n, i, max, min, a[100];
+ printf("Enter total number of elements:");
+ scanf("%d",&n);
+ printf("Enter values:");
+ for (i=0;imax)
+ {
+ max=a[i];
+ }
+ if (a[i]
+#include
+int merge(int arr[], int l, int m, int r)
+{
+ int i, j, k,c1=0,c2=0,c3=0,c4=0,c5=0,c6=0;
+ int n1 = m - l + 1;
+ int n2 = r - m;
+ int L[n1], R[n2];
+ for (i = 0; i < n1; i++){
+ L[i] = arr[l + i];c1++;}
+ for (j = 0; j < n2; j++){
+ R[j] = arr[m + 1 + j];c2++;}
+ L[n1] = 2147483647;
+ R[n2] = 2147483647;
+ i = 0;
+ j = 0;
+ k = l;
+ while (i < n1 && j < n2) {
+ if (L[i] <= R[j]) {
+ c3++;
+ arr[k] = L[i];
+ i++;
+ }
+ else {
+ c4++;
+ arr[k] = R[j];
+ j++;
+ }
+ k++;
+ }
+ while (i < n1) {
+ arr[k] = L[i];
+ c5++;
+ i++;
+ k++;
+ }
+ while (j < n2) {
+ arr[k] = R[j];
+ c6++;
+ j++;
+ k++;
+ }
+ return c1+c2+c3+c4+c5+c6;
+}
+int mergeSort(int arr[], int l, int r,int c1,int c2)
+{
+ if (l < r) {
+ int m = l + (r - l) / 2;
+ c1+=1;
+ mergeSort(arr, l, m,c1,c2);
+ c2+=1;
+ mergeSort(arr, m + 1, r,c1,c2);
+ int c = merge(arr, l, m, r);
+ return c1+c2+c;
+ }
+}
+void printArray(int A[], int s)
+{
+ for (int i = 0; i < s; i++)
+ printf("%d ",A[i]);
+ printf("\n");
+}
+void descending(int number[],int n)
+{
+ int i,j,a;
+ for (i = 0; i < n; ++i)
+ {
+ for (j = i + 1; j < n; ++j)
+ {
+ if (number[i] < number[j])
+ {
+ a = number[i];
+ number[i] = number[j];
+ number[j] = a;
+ }
+ }
+ }
+}
+int main()
+{
+ int n;
+ printf("Enter the number of elements: ");
+ scanf("%d",&n);
+ int arr[n];
+ for(int i=0;i
+
+int graph[4][3] = {{2,3,4}, {1,3,4}, {1,2,0}, {1,2,0}};
+
+void checkNeighbour(int i, int j){
+ int k, checkNeighbour = 0;
+
+ for(k=0; k<3; k++){
+ if(graph[i][k] == j){
+ checkNeighbour = 1;
+ }
+ }
+ printf("%d\t", checkNeighbour);
+}
+
+int main(){
+ int i, j;
+
+ for(i=0; i<4; i++){
+ for(j=1; j<=4; j++){
+ checkNeighbour(i,j);
+ }
+ printf("\n");
+ }
+}
\ No newline at end of file
diff --git a/C/readability.c b/C/readability.c
new file mode 100644
index 000000000..fba77911f
--- /dev/null
+++ b/C/readability.c
@@ -0,0 +1,61 @@
+// predicts grade-level of a text
+// based on Coleman-Liau index
+
+
+#include
+#include
+#include
+#include
+
+int main(void)
+
+{
+ //set initial count for letters,words,sentences to 0
+ int letters = 0;
+ int words = 1;
+ int sentences = 0;
+
+ //promot user for text
+ string s = get_string("Text:\n");
+
+ //calculate number of letters,words and sentences
+ for (int i = 0, n = strlen(s); i < n; i++)
+ {
+ if ((s[i] >= 65 && s[i] <= 90) || (s[i] >= 97 && s[i] <= 122))
+ {
+ letters++;
+ }
+
+ if (s[i] == ' ')
+ {
+ words++;
+ }
+
+ if ((s[i] == '.' || s[i] == '?') || s[i] == '!')
+ {
+ sentences++;
+ }
+ }
+
+ // calculate "value" of index
+ float value = ((0.0588 * 100 * ((float) letters / (float) words)) - (0.296 * 100 * ((float) sentences / (float) words)) - 15.8);
+
+ // round-off index value to nearest integer
+ int index = round(value);
+
+ //printf grade of the text
+ if (index >= 1 && index < 16)
+ {
+ printf("Grade %i\n", index);
+ }
+
+ else if (index >= 16)
+ {
+ printf(" Grade 16+\n");
+ }
+
+ else if (index < 1)
+ {
+ printf("Before Grade 1\n");
+ }
+}
diff --git a/C/selection sort .c b/C/selection sort .c
new file mode 100644
index 000000000..f8ebdc9f1
--- /dev/null
+++ b/C/selection sort .c
@@ -0,0 +1,36 @@
+#include
+int main(void)
+{
+ int a[100],n,i,j,b;
+printf("enter the number of values to be inserted");
+scanf("%d",&n);
+for(i=0;i
+
+int main()
+{
+ int t,n,a[200],i,j,k,l,m;
+ scanf("%d",&t);
+ while(t--)
+ {
+ scanf("%d",&n);
+ m=1;
+ a[0]=1;
+ for(j=2;j<=n;j++)
+ {
+ l=0;
+ for(k=0;k=0;i--)
+ printf("%d",a[i]);
+
+ printf("\n");
+ }
+ return 0;
+}
\ No newline at end of file
diff --git a/C/sortingalgo.c b/C/sortingalgo.c
new file mode 100644
index 000000000..61c1bc0f0
--- /dev/null
+++ b/C/sortingalgo.c
@@ -0,0 +1,111 @@
+ //Write a C program to sort an array of n number of elements using bubble sort, selection sort, and insertion sort.
+// Assume that n >5. Print the sorted output after each pass.
+
+#include
+
+//function to print array
+void printArray(int arr[], int size)
+{
+ int i;
+ for (i=0; i < size; i++)
+ printf("%d ", arr[i]);
+ printf("\n");
+}
+
+//Function to sort an array using bubblesort algorithm
+int bubblesort(int array[],int n)
+{
+ int temp,i,j;
+ for(i = 0; i < n-1; i++)
+ {
+ for(j = 0; j < n-i-1; j++)
+ {
+ if(array[j]>array[j+1])
+ {
+ temp=array[j];
+ array[j]=array[j+1];
+ array[j+1]=temp;
+ }
+ }
+ printArray(array,n);
+ }
+ return 0;
+}
+//Function to sort an array using selectionsort algorithm
+int selectionsort(int array[],int n)
+{
+ int min,i,j,temp;
+ for (i=0;i<=n-2;i++)
+ {
+ min=i;
+ for(j=i+1;j<=n-1;j++)
+ {
+ if(array[j]=0))
+ {
+ array[j+1]=array[j];
+ j=j-1;
+ }
+
+ array[j+1]=temp;
+ printArray(array,n);
+ }
+
+ return 0;
+}
+
+int main()
+{
+ int array[50]={0};
+ int n,sort;
+
+ printf("How many numbers are you going to enter?");
+ scanf("%d",&n);
+
+ for(int i=0;i
+int main()
+{
+ int a, b;
+ printf("Enter value of a:");
+ scanf("%d",&a);
+ printf("Enter value of b:");
+ scanf("%d", &b);
+ a=a^b;
+ b=a^b;
+ a=a^b;
+ printf("After swapping:\na=%d", a);
+ printf("\nb=%d", b);
+}
diff --git a/C/temperatureConverter.c b/C/temperatureConverter.c
new file mode 100644
index 000000000..b37b49df4
--- /dev/null
+++ b/C/temperatureConverter.c
@@ -0,0 +1,13 @@
+//temperature converter from celsius to fahrenheit
+
+#include
+
+int main()
+{
+float fahrenheit, celsius;
+celsius = 24;
+fahrenheit =( (celsius*9)/5)+32;
+printf("Temperature in fahrenheit is: %f",fahrenheit);
+return (0);
+
+}
diff --git a/C/transpose sequential search.c b/C/transpose sequential search.c
new file mode 100644
index 000000000..6157622d2
--- /dev/null
+++ b/C/transpose sequential search.c
@@ -0,0 +1,43 @@
+#include
+int main()
+{
+ int a[10],n,i,t,element;
+printf("enter the number of values to be inserted");
+scanf("%d",&n);
+for(i=0;i
+using namespace std;
+
+int main() {
+
+ int i,j;
+
+ for(i=2;i<101;i++) {
+ bool x=true;
+
+ for (j=2;j<(i-1);j++) {
+
+ if(i%j==0) {
+ x=false;
+ break;
+ }
+
+ }
+
+ if(x==true) {
+ cout<
+using namespace std;
+
+#define ll long long int
+#define vi vector
+#define vvi vector
+#define pb push_back
+#define fo(i,a,b) for(int i=a ; in || y<1 || y>m)
+ return false;
+ if(vis[x][y]==1)
+ return false;
+ else
+ return true;
+
+}
+void dfs(ll x,ll y)
+{
+ vis[x][y]=1;
+ if(isValid(x-1,y))
+ dfs(x-1,y);
+ if(isValid(x,y+1))
+ dfs(x,y+1);
+ if(isValid(x+1,y))
+ dfs(x+1,y);
+ if(isValid(x,y-1))
+ dfs(x,y-1);
+}
+int main()
+{
+ ios_base::sync_with_stdio(0);
+ cin.tie(0);
+ cout.tie(0);
+
+ int t;
+ // cin>>t;
+ // t=1;
+ while(t--)
+ {
+ ll ar[1001][1001];
+ cin>>n>>m;
+ for(ll i=1;i<=n;i++)
+ {
+ for(ll j=1;j<=m;j++)
+ cin>>ar[i][j];
+ }
+ //connected components
+ // ll cc=0;
+ // for(ll i=1;i<=n;i++)
+ // {
+ // for(ll j=1;j<=m;j++)
+ // {
+ // if(ar[i][j]==1 && vis[i][j]==0)
+ // dfs(i,j);
+ // }
+ // }
+ dfs(1,1);
+ }
+
+ return 0;
+}
\ No newline at end of file
diff --git a/CPP/3-way Merge Sort.cpp b/CPP/3-way Merge Sort.cpp
new file mode 100644
index 000000000..b4566802c
--- /dev/null
+++ b/CPP/3-way Merge Sort.cpp
@@ -0,0 +1,158 @@
+// C++ Program to perform 3 way Merge Sort
+#include
+using namespace std;
+
+/* Merge the sorted ranges [low, mid1), [mid1,mid2)
+and [mid2, high) mid1 is first midpoint
+index in overall range to merge mid2 is second
+midpoint index in overall range to merge*/
+void merge(int gArray[], int low, int mid1,
+ int mid2, int high, int destArray[])
+{
+ int i = low, j = mid1, k = mid2, l = low;
+
+ // choose smaller of the smallest in the three ranges
+ while ((i < mid1) && (j < mid2) && (k < high))
+ {
+ if(gArray[i] < gArray[j])
+ {
+ if(gArray[i] < gArray[k])
+ {
+ destArray[l++] = gArray[i++];
+ }
+ else
+ {
+ destArray[l++] = gArray[k++];
+ }
+ }
+ else
+ {
+ if(gArray[j] < gArray[k])
+ {
+ destArray[l++] = gArray[j++];
+ }
+ else
+ {
+ destArray[l++] = gArray[k++];
+ }
+ }
+ }
+
+ // case where first and second ranges
+ // have remaining values
+ while ((i < mid1) && (j < mid2))
+ {
+ if(gArray[i] < gArray[j])
+ {
+ destArray[l++] = gArray[i++];
+ }
+ else
+ {
+ destArray[l++] = gArray[j++];
+ }
+ }
+
+ // case where second and third ranges
+ // have remaining values
+ while ((j < mid2) && (k < high))
+ {
+ if(gArray[j] < gArray[k])
+ {
+ destArray[l++] = gArray[j++];
+ }
+ else
+ {
+ destArray[l++] = gArray[k++];
+ }
+ }
+
+ // case where first and third ranges have
+ // remaining values
+ while ((i < mid1) && (k < high))
+ {
+ if(gArray[i] < gArray[k])
+ {
+ destArray[l++] = gArray[i++];
+ }
+ else
+ {
+ destArray[l++] = gArray[k++];
+ }
+ }
+
+ // copy remaining values from the first range
+ while (i < mid1)
+ destArray[l++] = gArray[i++];
+
+ // copy remaining values from the second range
+ while (j < mid2)
+ destArray[l++] = gArray[j++];
+
+ // copy remaining values from the third range
+ while (k < high)
+ destArray[l++] = gArray[k++];
+}
+
+
+/* Performing the merge sort algorithm on the
+given array of values in the rangeof indices
+[low, high). low is minimum index, high is
+maximum index (exclusive) */
+void mergeSort3WayRec(int gArray[], int low,
+ int high, int destArray[])
+{
+ // If array size is 1 then do nothing
+ if (high - low < 2)
+ return;
+
+ // Splitting array into 3 parts
+ int mid1 = low + ((high - low) / 3);
+ int mid2 = low + 2 * ((high - low) / 3) + 1;
+
+ // Sorting 3 arrays recursively
+ mergeSort3WayRec(destArray, low, mid1, gArray);
+ mergeSort3WayRec(destArray, mid1, mid2, gArray);
+ mergeSort3WayRec(destArray, mid2, high, gArray);
+
+ // Merging the sorted arrays
+ merge(destArray, low, mid1, mid2, high, gArray);
+}
+
+void mergeSort3Way(int gArray[], int n)
+{
+ // if array size is zero return null
+ if (n == 0)
+ return;
+
+ // creating duplicate of given array
+ int fArray[n];
+
+ // copying alements of given array into
+ // duplicate array
+ for (int i = 0; i < n; i++)
+ fArray[i] = gArray[i];
+
+ // sort function
+ mergeSort3WayRec(fArray, 0, n, gArray);
+
+ // copy back elements of duplicate array
+ // to given array
+ for (int i = 0; i < n; i++)
+ gArray[i] = fArray[i];
+}
+
+// Driver Code
+int main()
+{
+ int data[] = {45, -2, -45, 78, 30,
+ -42, 10, 19, 73, 93};
+ mergeSort3Way(data,10);
+ cout << "After 3 way merge sort: ";
+ for (int i = 0; i < 10; i++)
+ {
+ cout << data[i] << " ";
+ }
+ return 0;
+}
+
+// This code is contributed by Rashmi Kumari
diff --git a/CPP/Alphacode.cpp b/CPP/Alphacode.cpp
new file mode 100644
index 000000000..737143543
--- /dev/null
+++ b/CPP/Alphacode.cpp
@@ -0,0 +1,87 @@
+/*AlphaCode-Question
+
+Alice and Bob need to send secret messages to each other and are discussing ways to encode their messages:
+Alice: “Let’s just use a very simple code: We’ll assign ‘A’ the code word 1, ‘B’ will be 2, and so on down to ‘Z’ being assigned 26.â€
+
+Bob: “That’s a stupid code, Alice. Suppose I send you the word ‘BEAN’ encoded as 25114. You could decode that in many different ways!â€
+
+Alice: “Sure you could, but what words would you get? Other than ‘BEAN’, you’d get ‘BEAAD’, ‘YAAD’, ‘YAN’, ‘YKD’ and ‘BEKD’. I think you would be able to figure out the correct decoding. And why would you send me the word ‘BEAN’ anyway?â€
+
+Bob: “OK, maybe that’s a bad example, but I bet you that if you got a string of length 5000 there would be tons of different decodings and with that many you would find at least two different ones that would make sense.â€
+
+Alice: “How many different decodings?â€
+
+Bob: “Jillions!â€
+For some reason, Alice is still unconvinced by Bob’s argument, so she requires a program that will determine how many decodings there can be for a given string using her code.
+Input
+Input will consist of multiple input sets. Each set will consist of a single line of at most 5000 digits representing a valid encryption (for example, no line will begin with a 0). There will be no spaces between the digits. An input line of ‘0’ will terminate the input and should not be processed.
+Output
+For each input set, output the number of possible decodings for the input string. Print your answer taking modulo "10^9+7"
+Sample Input:
+25114
+1111111111
+3333333333
+0
+Sample Output:
+6
+89
+1*/
+
+
+
+#include
+using namespace std;
+
+int num_codes(int* n, int size) {
+ if (size == 1) {
+ return 1;
+ }
+ if (size == 0) {
+ return 1;
+ }
+ int output = num_codes(n, size - 1);
+ if (output[size - 2] * 10 + output[size - 1] <= 26) {
+ output += num_codes(n, size -2);
+ }
+ return output;
+}
+
+int num_codes_i(int * input, int size) {
+ int* output = new int[size + 1];
+ output[0] = 1;
+ output[1] = 1;
+
+ for (int i = 2; i <= size; i++) {
+ output[i] = output[i - 1];
+ if (input[i-2] *10 + input[i - 1] <= 26) {
+ output[i] += output[i - 2];
+ }
+ }
+ int ans = output[size];
+ delete [] output;
+ return ans;
+}
+
+int num_codes2(int* n, int size, int* arr) {
+ if (size == 1) {
+ return 1;
+ }
+ if (size == 0) {
+ return 1;
+ }
+ if (arr[size] > 0) {
+ return arr[size];
+ }
+
+ int output = num_codes(n, size - 1);
+ if (output[size - 2] * 10 + output[size - 1] <= 26) {
+ output += num_codes(n, size -2);
+ }
+ arr[size] = output;
+ return output;
+}
+
+
+int main() {
+
+}
diff --git a/CPP/BFS.cpp b/CPP/BFS.cpp
new file mode 100644
index 000000000..9ff21223a
--- /dev/null
+++ b/CPP/BFS.cpp
@@ -0,0 +1,48 @@
+#include
+#include
+#include
+#pragma GCC optimize("Ofast")
+#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,fma")
+#pragma GCC optimize("unroll-loops")
+const unsigned int M = 1000000007;
+using namespace std;
+// Check
+using namespace __gnu_pbds;
+typedef tree,rb_tree_tag,tree_order_statistics_node_update> T_set; // PBDS_set
+typedef tree,rb_tree_tag,tree_order_statistics_node_update> T_multiset; // PBDS_multiset
+
+void solve()
+{
+ int n ,m,u,v;
+ cin>>n>>m;
+ vector> adj(n+1);
+ vector vis(n+1,false);
+ for(int i = 0; i < n ; i++ ){
+ cin>>u>>v;
+ adj[u].push_back(v);
+ adj[v].push_back(u);
+ }
+ queue temp;
+ temp.push(1);
+ vis[1] = true;
+ while(!temp.empty()){
+ int curr = temp.front();
+ cout<
+#include
+
+using namespace std;
+
+class node {
+ public:
+ int data;
+ node *left, *right;
+}*root;
+
+node* GetNode(int d) {
+ node *nn=new(node);
+ nn->left = NULL;
+ nn->right = NULL;
+ nn->data = d;
+ return nn;
+}
+
+void InOrder(node *root) {
+ if(root == NULL)
+ return ;
+ InOrder(root->left);
+ cout<data<<" ";
+ InOrder(root->right);
+}
+
+void StoreData(node *root,set &s){ //&s reference of original set
+ if(root == NULL)
+ return ;
+ StoreData(root->left,s);
+ s.insert(root->data);
+ StoreData(root->right,s);
+}
+
+void ConvertToBST(node *root, auto &it) {
+ if(root == NULL)
+ return ;
+ ConvertToBST(root->left, it);
+ root->data = *it;
+ it++;
+ ConvertToBST(root->right, it);
+}
+
+int main()
+{
+ root = GetNode(8);
+ root->left = GetNode(3);
+ root->right = GetNode(5);
+ root->left->left = GetNode(10);
+ root->left->right = GetNode(2);
+ root->right->left = GetNode(4);
+ root->right->right = GetNode(6);
+ InOrder(root);
+
+ set s;
+ StoreData(root,s);
+ auto it = s.begin();
+ ConvertToBST(root,it);
+ InOrder(root);
+}
diff --git a/CPP/Combination Sum.cpp b/CPP/Combination Sum.cpp
new file mode 100644
index 000000000..e0987cb4e
--- /dev/null
+++ b/CPP/Combination Sum.cpp
@@ -0,0 +1,52 @@
+//Objective is to find the number of subsets that can have the sum as target.
+/*
+ Lets take an example to understand it much better.
+ Consider array given as arr[]={2,3,6,7};
+ And target as 7.
+ So possible combinations are:
+ 1. [2,2,3]
+ 2. [7]
+ So only 2 subsets are possible.
+
+ NOTE -> We can choose a number any number of times i.e. Repetition is allowed.
+
+ To solve such problems recursion is the best approach to go for.Now for every index we have two options
+ 1. Choose the index and decrease the sum, and next time a recusrive call is made start from the same indx.
+ 2. Move ahead with the next index and try out the possible combinations by not including the curr element.
+
+ We will need a data structure that can store the sum at every recursive call.
+ So i have made use of a vector. You can choose whatever feels right to you!!.
+
+ So lets move on to code :)
+*/
+#include
+using namespace std;
+
+void helper(vector&arr,vector>&ans,vectortemp,int target,int start_index,int curr_sum){
+
+ if(target == curr_sum){ans.push_back(temp);return;} // If we find current sum to be equal to target then we can push that subset into our 'ans' array.
+ if(start_index>=arr.size()){return ;} //Base case1 - if current postion exceeds the array size then reutrn.
+ if(curr_sum>target){return ;} // Base case2- if at ith postion we see that the value of curr_sum exceeds then target then their is no meaning in moving ahead.
+ temp.push_back(arr[start_index]);
+ helper(arr,ans,temp,target,start_index,curr_sum+arr[start_index]); // Recursive call with current element included
+ temp.pop_back(); // popping out the element
+ helper(arr,ans,temp,target,start_index+1,curr_sum); //Backtrack.
+}
+
+int main(){
+
+ vectorarr{2,3,6,7};
+ int n=arr.size(),target=7,curr_sum=0,start_index=0,i,j;
+ vector>ans; // To store all of the subsets.
+ vectortemp; // To store possible numbers that can form a subset.
+ helper(arr,ans,temp,target,start_index,curr_sum); // A helper function for recursive calls.
+
+ cout<<"Subsets with sum as "<
+using namespace std;
+#define ll long long
+
+//only for numbers in the range -1e3 to 1e3 :
+void counting_sort(vector &v){
+ vector hash(int(1e6), 0) ;
+ for(auto x : v){
+ hash[int(1e3) + x]++;
+ }
+ v.clear();
+ for(int j = 0 ; j < hash.size() ; j++){
+ if(hash[j] > 0){
+ for(int i = 0 ; i < hash[j] ; i++){
+ v.push_back(j-int(1e3));
+ }
+ }
+ }
+}
+void solve(){
+ ll n ; cin >> n ;
+ vector v(n);
+ for(auto &x : v){
+ cin >> x;
+ }
+ counting_sort(v);
+ for(auto x : v){
+ cout << x << " ";
+ }
+}
+
+int main()
+{
+ ios_base::sync_with_stdio(false);
+ cin.tie(NULL);
+
+ solve();
+}
diff --git a/CPP/Data Structures/FloydWarshall.cpp b/CPP/Data Structures/FloydWarshall.cpp
new file mode 100644
index 000000000..c4837c9e4
--- /dev/null
+++ b/CPP/Data Structures/FloydWarshall.cpp
@@ -0,0 +1,53 @@
+#include
+using namespace std;
+
+#define V 4 //No of vertices
+
+void floyd_warshall(int graph[V][V])
+{
+ int dist[V][V];
+
+ //Assign all values of graph to allPairs_SP
+ for (int i = 0; i < V; ++i)
+ for (int j = 0; j < V; ++j)
+ dist[i][j] = graph[i][j];
+
+ //Find all pairs shortest path by trying all possible paths
+ for (int k = 0; k < V; ++k) //Try all intermediate nodes
+ for (int i = 0; i < V; ++i) //Try for all possible starting position
+ for (int j = 0; j < V; ++j) //Try for all possible ending position
+ {
+ if (dist[i][k] == INT_MAX || dist[k][j] == INT_MAX) //SKIP if K is unreachable from i or j is unreachable from k
+ continue;
+ else if (dist[i][k] + dist[k][j] < dist[i][j]) //Check if new distance is shorter via vertex K
+ dist[i][j] = dist[i][k] + dist[k][j];
+ }
+
+ //Check for negative edge weight cycle
+ for (int i = 0; i < V; ++i)
+ if (dist[i][i] < 0)
+ {
+ cout << "Negative edge weight cycle is present\n";
+ return;
+ }
+
+ //Print Shortest Path Graph
+ //(Values printed as INT_MAX defines there is no path)
+ for (int i = 0; i < V; ++i)
+ {
+ for (int j = 0; j < V; ++j)
+ cout << i << " to " << j << " distance is " << dist[i][j] << "\n";
+ cout << "=================================\n";
+ }
+}
+
+int main()
+{
+ int graph[V][V] = {{0, 3, INT_MAX, 5},
+ {2, 0, INT_MAX, 8},
+ {INT_MAX, 1, 0, INT_MAX},
+ {INT_MAX, INT_MAX, 2}};
+
+ floyd_warshall(graph);
+ return 0;
+}
\ No newline at end of file
diff --git a/CPP/Data Structures/Hashmap/hashmap.cpp b/CPP/Data Structures/Hashmap/hashmap.cpp
new file mode 100644
index 000000000..42888565d
--- /dev/null
+++ b/CPP/Data Structures/Hashmap/hashmap.cpp
@@ -0,0 +1,27 @@
+#include
+#include "hashmapClass.h"
+#include
+using namespace std;
+
+
+int main (){
+ map ourmap(13);
+ string key;
+ int value;
+ cout << "Enter key (Enter 0 for termination) : ";
+ cin >> key;
+ while (key != "0"){
+ cout << "Enter Value of " << key << " : ";
+ cin >> value;
+ ourmap.insert(key,value);
+ cout << "Enter another key (Enter 0 for termination) : ";
+ cin >> key;
+ }
+ cout << endl;
+ ourmap.display();
+
+ ourmap.removeKey("Gopal");
+ cout << "List after removing key" << endl;
+ ourmap.display();
+ return 0;
+}
\ No newline at end of file
diff --git a/CPP/Data Structures/Hashmap/hashmapClass.h b/CPP/Data Structures/Hashmap/hashmapClass.h
new file mode 100644
index 000000000..199ca57f0
--- /dev/null
+++ b/CPP/Data Structures/Hashmap/hashmapClass.h
@@ -0,0 +1,116 @@
+#include
+#include "node.h"
+#include
+using namespace std;
+
+template
+class map {
+ public:
+ node ** array;
+ int count;
+ int bucketSize;
+
+ map(int bucketSize){
+ this -> bucketSize = bucketSize;
+ count = 0;
+ array = new node*[bucketSize];
+ for (int i =0;i * temp = array[bucketIndex];
+ while (temp != NULL){
+ if (temp -> key == key){
+ temp -> value = value;
+ return;
+ }
+ temp = temp -> next;
+ }
+ temp = array[bucketIndex];
+ node * newNode = new node(key,value);
+ newNode -> next = temp;
+ array[bucketIndex] = newNode;
+ count++;
+ }
+
+ t getValue(string key){
+ int bucketIndex = getBucketIndex(key);
+ node * head = array[bucketIndex];
+ while (head != NULL){
+ if (head -> key == key){
+ return head -> value;
+ }
+ head = head -> next;
+ }
+ return 0;
+ }
+
+ t removeKey(string key){
+ int bucketIndex = getBucketIndex(key);
+ cout << "bucketIndex for " << key << " is " << bucketIndex << endl;
+ node * head = array[bucketIndex];
+ cout << "Key " << head -> key << endl;
+ node * prev = NULL;
+ while (head != NULL){
+ cout << "This is working";
+ if (head -> key == key){
+ if (prev == NULL){
+ array[bucketIndex] = head -> next;
+
+ }else{
+ prev -> next = head -> next;
+ }
+ cout << "This is working too";
+ head -> next = NULL;
+ t value = head -> value;
+ delete head;
+ count--;
+ return value;
+ }
+ prev = head;
+ head = head -> next;
+ }
+ return 0;
+ }
+
+
+ void display(){
+ for (int i =0;i * head){
+ while(head != NULL){
+ cout << "(" << head -> key << " , " << head -> value << ")" << endl;
+ head = head -> next;
+ }
+ }
+};
\ No newline at end of file
diff --git a/CPP/Data Structures/Hashmap/node.h b/CPP/Data Structures/Hashmap/node.h
new file mode 100644
index 000000000..94d2b7f9a
--- /dev/null
+++ b/CPP/Data Structures/Hashmap/node.h
@@ -0,0 +1,21 @@
+#include
+#include
+using namespace std;
+
+template
+class node {
+ public:
+ string key;
+ t value;
+ node * next;
+
+ node(string key, t value){
+ this -> key = key;
+ this -> value = value;
+ next = NULL;
+ }
+
+ ~node(){
+ delete next;
+ }
+};
\ No newline at end of file
diff --git a/CPP/Data Structures/Implementation-of-LinkedList.cpp b/CPP/Data Structures/Implementation-of-LinkedList.cpp
new file mode 100644
index 000000000..3c48fe70c
--- /dev/null
+++ b/CPP/Data Structures/Implementation-of-LinkedList.cpp
@@ -0,0 +1,63 @@
+#include
+using namespace std;
+
+struct Node
+{
+ int data;
+ Node *next;
+ Node(int x)
+ {
+ data = x;
+ next = NULL;
+ }
+};
+Node *insertend(Node *head, int data)
+{
+ if (head == NULL || head->next == NULL)
+ {
+ return head;
+ }
+ Node *temp = new Node(data);
+ Node *curr = head;
+ while (curr->next != NULL)
+ {
+ curr = curr->next;
+ }
+ curr->next = temp;
+ temp->next = NULL;
+ return head;
+}
+void show(Node *head)
+{
+ Node *curr = head;
+ while (curr != NULL)
+ {
+ cout << curr->data << " ";
+ curr = curr->next;
+ }
+}
+
+int main()
+{
+ Node *head = new Node(10);
+ Node *temp1 = new Node(20);
+ Node *temp2 = new Node(30);
+ head->next = temp1;
+ temp1->next = temp2;
+ cout << "Initial List : ";
+ show(head);
+ cout << endl;
+ cout << "No of values to be inserted : ";
+ int n;
+ cin >> n;
+ cout << "Enter the values : ";
+ for (int i = 0; i < n; i++)
+ {
+ int data;
+ cin >> data;
+ head = insertend(head, data);
+ }
+
+ cout << "List after addition : ";
+ show(head);
+}
\ No newline at end of file
diff --git a/CPP/Data Structures/Linked List/Basics Of LL.cpp b/CPP/Data Structures/Linked List/Basics Of LL.cpp
new file mode 100644
index 000000000..c84c2314c
--- /dev/null
+++ b/CPP/Data Structures/Linked List/Basics Of LL.cpp
@@ -0,0 +1,113 @@
+#include
+using namespace std;
+
+struct Node
+{
+ int data;
+ Node *next;
+ Node(int x)
+ {
+ data=x;
+ next=NULL;
+ }
+};
+
+Node* Iend(Node *head,int x)
+{
+ Node *temp=new Node(x);
+ if(head==NULL)
+ return temp;
+ Node *curr=head;
+ while(curr->next!=nullptr)
+ {
+ curr=curr->next;
+ }
+ curr->next=temp;
+ return head;
+
+}
+
+Node* Ibeg(Node *head, int x)
+{
+ Node *temp=new Node(x);
+ if(head==nullptr)
+ {
+ return temp;
+ }
+
+ Node *curr=head;
+ head=temp;
+ head->next=curr;
+ return head;
+}
+
+Node *Imiddle(Node *head, int x, int pos)
+{
+ Node *temp=new Node(x);
+ Node *curr=head;
+ if(pos==1)
+ {
+ temp->next=head;
+ return temp;
+ }
+ for(int i=1; i<=pos-2 && curr!=nullptr; i++)// goes till that node where changes happen
+ {
+ curr=curr->next;
+ }
+ if(curr==nullptr)
+ {
+ return head;
+ }
+ temp->next=curr->next;
+ curr->next=temp;
+ return head;
+}
+
+void disp(Node* head)
+{
+ Node* k=head;
+ if(head == nullptr)
+ {
+ cout<<"The LL is Empty";
+ return;
+ }
+ while(k!=nullptr)
+ {
+ cout<data<<" ";
+ k=k->next;
+ }
+ return;
+}
+
+int main()
+{
+ int n;
+ cin>>n;
+ Node* head=NULL;
+ for(int i=1;i<=n;i++)
+ {
+ int k;
+ cin>>k;
+ head=Iend(head,k);
+ }
+
+ disp(head);
+ int m;
+ cin>>m;
+ for(int i=1;i<=m;i++)
+ {
+ int k;
+ cin>>k;
+ head=Ibeg(head,k);
+ }
+
+ disp(head);
+ int l,pos;
+ cin>>l>>pos;
+ head=Imiddle(head,l,pos);
+
+ disp(head);
+
+ return 0;
+
+}
\ No newline at end of file
diff --git a/CPP/Data Structures/Linked List/Fold a Linked List.png b/CPP/Data Structures/Linked List/Fold a Linked List.png
new file mode 100644
index 000000000..9b63d4861
Binary files /dev/null and b/CPP/Data Structures/Linked List/Fold a Linked List.png differ
diff --git a/CPP/Data Structures/Linked List/FoldLL.cpp b/CPP/Data Structures/Linked List/FoldLL.cpp
new file mode 100644
index 000000000..0bed4e2fb
--- /dev/null
+++ b/CPP/Data Structures/Linked List/FoldLL.cpp
@@ -0,0 +1,123 @@
+#include
+using namespace std;
+
+struct Node
+{
+ int data;
+ Node *next;
+ Node(int x)
+ {
+ data=x;
+ next=NULL;
+ }
+};
+
+Node* Iend(Node *head,int x)
+{
+ Node *temp=new Node(x);
+ if(head==NULL)
+ return temp;
+ Node *curr=head;
+ while(curr->next!=nullptr)
+ {
+ curr=curr->next;
+ }
+ curr->next=temp;
+ return head;
+
+}
+
+void disp(Node* head)
+{
+ Node* k=head;
+ if(head == nullptr)
+ {
+ cout<<"The LL is Empty";
+ return;
+ }
+ while(k!=nullptr)
+ {
+ cout<data<<" - > ";
+ k=k->next;
+ }
+ return;
+}
+Node* findM(Node *head)
+{
+ if(head == nullptr || head->next==nullptr)
+ {
+
+ return head;
+ }
+ Node *f=head, *s=head;
+ int c=0;
+ while(f->next != nullptr && f->next->next !=nullptr)
+ {
+ c++;
+ s=s->next;
+ f=f->next->next;
+ }
+
+ return s;
+}
+
+Node *Reverse(Node *head)
+{
+
+ if(head==nullptr||head->next==nullptr)
+ {
+ return head;
+ }
+
+ Node *k=Reverse(head->next);
+ Node *t=head->next;
+ t->next=head;
+ head->next=nullptr;
+ return k;
+}
+
+Node *fold(Node *head)
+{
+ if(head==nullptr || head->next == nullptr)
+ {
+ return head;
+ }
+ Node *mid=findM(head);
+ Node *nh=mid->next;
+ mid->next=nullptr;
+ nh=Reverse(nh);
+
+ Node *c1=head;
+ Node *c2=nh;
+ Node *f1=nullptr;
+ Node *f2=NULL;
+ while(c2!=nullptr)
+ {
+ f1=c1->next;
+ f2=c2->next;
+
+ c1->next=c2;
+ c2->next=f1;
+
+ c1=f1;
+ c2=f2;
+ }
+ return head;
+}
+
+int main()
+{
+ int n;
+ cin>>n;
+ Node* head=NULL;
+ for(int i=1;i<=n;i++)
+ {
+ int k;
+ cin>>k;
+ head=Iend(head,k);
+ }
+
+ head=fold(head);
+ disp(head);
+ return 0;
+}
\ No newline at end of file
diff --git a/CPP/Data Structures/Linked List/Merge Sort LL.png b/CPP/Data Structures/Linked List/Merge Sort LL.png
new file mode 100644
index 000000000..d65b90d84
Binary files /dev/null and b/CPP/Data Structures/Linked List/Merge Sort LL.png differ
diff --git a/CPP/Data Structures/Linked List/MergeSort.cpp b/CPP/Data Structures/Linked List/MergeSort.cpp
new file mode 100644
index 000000000..1fe0c5682
--- /dev/null
+++ b/CPP/Data Structures/Linked List/MergeSort.cpp
@@ -0,0 +1,132 @@
+#include
+using namespace std;
+
+struct Node
+{
+ int data;
+ Node *next;
+ Node(int x)
+ {
+ data=x;
+ next=NULL;
+ }
+};
+
+Node* Iend(Node *head,int x)
+{
+ Node *temp=new Node(x);
+ if(head==NULL)
+ return temp;
+ Node *curr=head;
+ while(curr->next!=nullptr)
+ {
+ curr=curr->next;
+ }
+ curr->next=temp;
+ return head;
+
+}
+
+void disp(Node* head)
+{
+ Node* k=head;
+ if(head == nullptr)
+ {
+ cout<<"The LL is Empty";
+ return;
+ }
+ while(k!=nullptr)
+ {
+ cout<data<<" - > ";
+ k=k->next;
+ }
+}
+
+Node *MergeLL(Node *l1,Node *l2)
+{
+ if(l1==nullptr || l2==nullptr)
+ {
+ return l1 != nullptr?l1:l2;
+ }
+
+ Node *d=new Node(-1);
+ Node *c1=l1, *c2=l2, *p=d;
+ while(c1!=nullptr && c2!=nullptr)
+ {
+ if(c1->data < c2->data)
+ {
+ p->next=c1;
+ c1=c1->next;
+ }
+ else{
+ p->next=c2;
+ c2=c2->next;
+ }
+ p=p->next;
+ }
+
+ if(c1==nullptr)
+ {
+ p->next=c2;
+ }
+ else
+ {
+ p->next=c1;
+ }
+
+ return d->next;
+
+}
+
+Node *Mid(Node *head)
+{
+ if(head==nullptr || head->next==nullptr)
+ {
+ return head;
+ }
+ Node *f=head , *s=head;
+ while(f->next && f->next->next)
+ {
+ f=f->next->next;
+ s-s->next;
+ }
+
+ return s;
+}
+
+Node *mergesort(Node *head)
+{
+ if(head==nullptr || head->next==nullptr)
+ {
+ return head;
+ }
+ Node *mid=Mid(head);
+ Node *nh=mid->next;
+ mid->next=NULL;
+
+ Node *l1=mergesort(head);
+ Node *l2=mergesort(nh);
+
+ return MergeLL(l1,l2);
+}
+
+int main()
+{
+ int n;
+ cin>>n;
+ Node* head=NULL, *head1=NULL;
+ for(int i=1;i<=n;i++)
+ {
+ int k;
+ cin>>k;
+ head=Iend(head,k);
+ }
+
+ disp(head);
+ cout<
+using namespace std;
+
+struct Node
+{
+ int data;
+ Node *next;
+ Node(int x)
+ {
+ data=x;
+ next=NULL;
+ }
+};
+
+Node* Iend(Node *head,int x)
+{
+ Node *temp=new Node(x);
+ if(head==NULL)
+ return temp;
+ Node *curr=head;
+ while(curr->next!=nullptr)
+ {
+ curr=curr->next;
+ }
+ curr->next=temp;
+ return head;
+
+}
+
+void disp(Node* head)
+{
+ Node* k=head;
+ if(head == nullptr)
+ {
+ cout<<"The LL is Empty";
+ return;
+ }
+ while(k!=nullptr)
+ {
+ cout<data<<" - > ";
+ k=k->next;
+ }
+ return;
+}
+
+Node *sep(Node *head)
+{
+ if(head==NULL || head->next == NULL)
+ {
+ return head;
+ }
+
+ Node *DE=new Node(-1);
+ Node *DO=new Node(-1);
+ Node *et=DE, *ot=DO, *curr=head;
+ while(curr!=nullptr)
+ {
+ if( (curr->data) %2 == 0)
+ {
+ et->next=curr;
+ et=et->next;
+ }
+ else
+ {
+ ot->next=curr;
+ ot=ot->next;
+ }
+
+ curr=curr->next;
+ }
+
+ ot->next=nullptr;
+ et->next=DO->next;
+ return DE->next;
+}
+
+
+int main()
+{
+ int n;
+ cin>>n;
+ Node* head=NULL;
+ for(int i=1;i<=n;i++)
+ {
+ int k;
+ cin>>k;
+ head=Iend(head,k);
+ }
+
+ disp(head);
+ cout<
+using namespace std;
+
+struct Node
+{
+ int data;
+ Node *next;
+ Node(int x)
+ {
+ data=x;
+ next=NULL;
+ }
+};
+
+Node* Iend(Node *head,int x)
+{
+ Node *temp=new Node(x);
+ if(head==NULL)
+ return temp;
+ Node *curr=head;
+ while(curr->next!=nullptr)
+ {
+ curr=curr->next;
+ }
+ curr->next=temp;
+ return head;
+
+}
+
+void disp(Node* head)
+{
+ Node* k=head;
+ if(head == nullptr)
+ {
+ cout<<"The LL is Empty";
+ return;
+ }
+ while(k!=nullptr)
+ {
+ cout<data<<" ";
+ k=k->next;
+ }
+ return;
+}
+
+Node *RemDupli(Node *head)
+{
+ if(head==NULL||head->next==nullptr)
+ {
+ return head;
+ }
+
+ Node* temp=head;
+ for(Node *curr=head->next;curr!=nullptr;curr=curr->next)
+ {
+ if(curr->data==temp->data)
+ {
+ temp->next=curr->next;
+ }
+ else
+ {
+ temp=curr;
+ }
+ }
+}
+
+
+int main()
+{
+ int n;
+ cin>>n;
+ Node* head=NULL;
+ for(int i=1;i<=n;i++)
+ {
+ int k;
+ cin>>k;
+ head=Iend(head,k);
+ }
+
+ disp(head);
+
+ RemDupli(head);
+
+ cout<
+using namespace std;
+
+struct Node
+{
+ int data;
+ Node *next;
+ Node(int x)
+ {
+ data=x;
+ next=NULL;
+ }
+};
+
+Node* Iend(Node *head,int x)
+{
+ Node *temp=new Node(x);
+ if(head==NULL)
+ return temp;
+ Node *curr=head;
+ while(curr->next!=nullptr)
+ {
+ curr=curr->next;
+ }
+ curr->next=temp;
+ return head;
+
+}
+
+void disp(Node* head)
+{
+ Node* k=head;
+ if(head == nullptr)
+ {
+ cout<<"The LL is Empty";
+ return;
+ }
+ while(k!=nullptr)
+ {
+ cout<data<<" -> ";
+ k=k->next;
+ }
+ return;
+}
+
+Node* Rev(Node *head, int k)
+{
+ Node*curr=head;
+ Node* prev=nullptr,*next=nullptr;
+ int count=0;
+ while(curr!=nullptr && count< k)
+ {
+ next=curr->next;
+ curr->next=prev;
+ prev=curr;
+ curr=next;
+ count++;
+ }
+ if(next!=nullptr)
+ {
+ Node *rh=Rev(next,k);
+ head->next=rh;
+ }
+ return prev;
+}
+
+
+int main()
+{
+ int n;
+ cin>>n;
+ Node* head=NULL;
+ for(int i=1;i<=n;i++)
+ {
+ int k;
+ cin>>k;
+ head=Iend(head,k);
+ }
+
+ //disp(head);
+ int k;
+ cin>>k;
+ head=Rev(head,k);
+ cout<
+using namespace std;
+
+struct Node
+{
+ int data;
+ Node *next;
+ Node(int x)
+ {
+ data=x;
+ next=NULL;
+ }
+};
+
+Node* Iend(Node *head,int x)
+{
+ Node *temp=new Node(x);
+ if(head==NULL)
+ return temp;
+ Node *curr=head;
+ while(curr->next!=nullptr)
+ {
+ curr=curr->next;
+ }
+ curr->next=temp;
+ return head;
+
+}
+
+void disp(Node* head)
+{
+ Node* k=head;
+ if(head == nullptr)
+ {
+ cout<<"The LL is Empty";
+ return;
+ }
+ while(k!=nullptr)
+ {
+ cout<data<<" ";
+ k=k->next;
+ }
+ return;
+}
+
+Node *Reverse(Node *head)
+{
+
+ if(head==nullptr||head->next==nullptr)
+ {
+ return head;
+ }
+
+ Node *k=Reverse(head->next);
+ Node *t=head->next;
+ t->next=head;
+ head->next=nullptr;
+ return k;
+}
+
+int main()
+{
+ int n;
+ cin>>n;
+ Node* head=NULL;
+ for(int i=1;i<=n;i++)
+ {
+ int k;
+ cin>>k;
+ head=Iend(head,k);
+ }
+ //disp(head);
+
+ cout<
+using namespace std;
+
+struct Node
+{
+ int data;
+ Node *next;
+ Node(int x)
+ {
+ data=x;
+ next=NULL;
+ }
+};
+
+Node* Iend(Node *head,int x)
+{
+ Node *temp=new Node(x);
+ if(head==NULL)
+ return temp;
+ Node *curr=head;
+ while(curr->next!=nullptr)
+ {
+ curr=curr->next;
+ }
+ curr->next=temp;
+ return head;
+
+}
+
+void disp(Node* head)
+{
+ Node* k=head;
+ if(head == nullptr)
+ {
+ cout<<"The LL is Empty";
+ return;
+ }
+ while(k!=nullptr)
+ {
+ cout<data<<" ";
+ k=k->next;
+ }
+ return;
+}
+Node *findM(Node *head)
+{
+ if(head == nullptr || head!=nullptr)
+ {
+ return head;
+ }
+ Node *f=head, *s=head;
+ while(f->next != nullptr && f->next->next !=nullptr)
+ {
+ s=s->next;
+ f=f->next->next;
+ }
+ return s;
+}
+
+Node *Reverse(Node *head)
+{
+ if(head==nullptr||head->next==nullptr)
+ {
+ return head;
+ }
+
+ Node *k=Reverse(head->next);
+ Node *t=head->next;
+ t->next=head;
+ head->next=nullptr;
+ return k;
+}
+
+bool Palindrome(Node *head)
+{
+ if(head == NULL || head->next == nullptr)
+ {
+ return head;
+ }
+ Node *mid=findM(head);
+ Node *nh=mid->next;
+ // cout<data<<" "<next->data;
+ mid->next=nullptr;
+ nh=Reverse(nh);
+ Node *i=head,*j=nh;
+ bool flag=true;
+ while(i != nullptr && j!=nullptr)
+ {
+ if(i->data != j->data)
+ {
+ flag=false;
+ break;
+ }
+ i=i->next;
+ j=j->next;
+ }
+
+ nh=Reverse(nh);
+ mid->next=nh;
+
+ return flag;
+}
+
+int main()
+{
+ int n;
+ cin>>n;
+ Node* head=NULL;
+ for(int i=1;i<=n;i++)
+ {
+ int k;
+ cin>>k;
+ head=Iend(head,k);
+ }
+
+ if(Palindrome(head))
+ {
+ cout<<"The LL is Palindromic";
+ }
+ else
+ {
+ cout<<"The LL is not Palindromic";
+ }
+
+ return 0;
+}
\ No newline at end of file
diff --git a/CPP/Data Structures/Stack Using Arrays/stack.cpp b/CPP/Data Structures/Stack Using Arrays/stack.cpp
new file mode 100644
index 000000000..37715c7d0
--- /dev/null
+++ b/CPP/Data Structures/Stack Using Arrays/stack.cpp
@@ -0,0 +1,25 @@
+#include
+#include "stackClass.cpp"
+using namespace std;
+
+// dynamic stack, changes it size acc to input
+
+int main (){
+ stack s1(5);
+ for (int i=0;i<5;i++){
+ s1.push(i+1);
+ }
+ s1.display();
+ stack s2(5);
+ s2.push('h');
+ s2.display();
+
+ s1.push(6);
+ s1.push(7);
+ s1.display();
+ cout << s1.getSize();
+ cout << endl;
+ stack s3;
+ cout << s3.getSize();
+ return 0;
+}
\ No newline at end of file
diff --git a/CPP/Data Structures/Stack Using Arrays/stackClass.cpp b/CPP/Data Structures/Stack Using Arrays/stackClass.cpp
new file mode 100644
index 000000000..5030e7f55
--- /dev/null
+++ b/CPP/Data Structures/Stack Using Arrays/stackClass.cpp
@@ -0,0 +1,75 @@
+#include
+#include
+using namespace std;
+
+template
+class stack {
+ t * p;
+ int top;
+ int size;
+ public :
+
+ stack(int size = 10){
+ top = -1;
+ this -> size = size;
+ p = new t[size];
+ }
+
+ int getSize(){
+ return size;
+ }
+
+ int getTop(){
+ return top;
+ }
+
+ bool isEmpty(){
+ if (top == -1){
+ return true;
+ }else {
+ return false;
+ }
+ }
+
+ bool isFull(){
+ if (top == size - 1){
+ return true;
+ }else {
+ return false;
+ }
+ }
+
+ void push(int data){
+ if (isFull()){
+ t * a = new t[size*2];
+ int i;
+ for (i=0;i
+using namespace std;
+
+template
+class node {
+ public:
+
+ v data;
+ node * next;
+
+ node(v data){
+ this -> data = data;
+ next = NULL;
+ }
+};
diff --git a/CPP/Data Structures/Stack Using Linked List/stack.cpp b/CPP/Data Structures/Stack Using Linked List/stack.cpp
new file mode 100644
index 000000000..f9b02c829
--- /dev/null
+++ b/CPP/Data Structures/Stack Using Linked List/stack.cpp
@@ -0,0 +1,21 @@
+#include
+#include "stackUsingLL.cpp"
+using namespace std;
+
+
+int main (){
+ stack s1;
+ s1.push(1);
+ s1.push(2);
+ s1.push(3);
+ cout << s1.getSize() << endl;
+ s1.display();
+ s1.pop();
+ cout << s1.getSize() << endl;
+ s1.display();
+
+ stack s2;
+ s2.push('h');
+ s2.display();
+ return 0;
+}
\ No newline at end of file
diff --git a/CPP/Data Structures/Stack Using Linked List/stackUsingLL.cpp b/CPP/Data Structures/Stack Using Linked List/stackUsingLL.cpp
new file mode 100644
index 000000000..6d5f683fe
--- /dev/null
+++ b/CPP/Data Structures/Stack Using Linked List/stackUsingLL.cpp
@@ -0,0 +1,58 @@
+#include
+#include "nodeClass.cpp"
+using namespace std;
+
+
+
+template
+class stack{
+ node * head;
+ node * tail;
+
+ int length;
+
+ public:
+ stack(){
+ head = NULL;
+ tail = NULL;
+ length = 0;
+ }
+
+ void push(t data){
+ node * newNode = new node(data);
+ if (head == NULL){
+ head = newNode;
+ tail = newNode;
+ }else {
+ tail -> next = newNode;
+ tail = newNode;
+ }
+ length++;
+ }
+
+ t pop(){
+ node * temp = head;
+ while (temp -> next != tail){
+ temp = temp -> next;
+ }
+ t data = tail -> data;
+ temp -> next = NULL;
+ tail = temp;
+ length--;
+ return data;
+ }
+
+ void display(){
+ node * temp = head;
+ while (temp != NULL){
+ cout << temp -> data << " ";
+ temp = temp -> next;
+ }
+ cout << endl;
+ }
+
+ int getSize(){
+ return length;
+ }
+
+};
\ No newline at end of file
diff --git a/CPP/Data Structures/Trees/Binary Trees/Diagonal_Traversal_of_a_binary_tree.cpp b/CPP/Data Structures/Trees/Binary Trees/Diagonal_Traversal_of_a_binary_tree.cpp
new file mode 100644
index 000000000..7faef435d
--- /dev/null
+++ b/CPP/Data Structures/Trees/Binary Trees/Diagonal_Traversal_of_a_binary_tree.cpp
@@ -0,0 +1,144 @@
+// { Driver Code Starts
+#include
+using namespace std;
+#define MAX_HEIGHT 100000
+
+// Tree Node
+struct Node
+{
+ int data;
+ Node* left;
+ Node* right;
+};
+
+// Utility function to create a new Tree Node
+Node* newNode(int val)
+{
+ Node* temp = new Node;
+ temp->data = val;
+ temp->left = NULL;
+ temp->right = NULL;
+
+ return temp;
+}
+
+
+vector diagonal(Node *root);
+
+// Function to Build Tree
+Node* buildTree(string str)
+{
+ // Corner Case
+ if(str.length() == 0 || str[0] == 'N')
+ return NULL;
+
+ // Creating vector of strings from input
+ // string after spliting by space
+ vector ip;
+
+ istringstream iss(str);
+ for(string str; iss >> str; )
+ ip.push_back(str);
+
+ // Create the root of the tree
+ Node* root = newNode(stoi(ip[0]));
+
+ // Push the root to the queue
+ queue queue;
+ queue.push(root);
+
+ // Starting from the second element
+ int i = 1;
+ while(!queue.empty() && i < ip.size()) {
+
+ // Get and remove the front of the queue
+ Node* currNode = queue.front();
+ queue.pop();
+
+ // Get the current node's value from the string
+ string currVal = ip[i];
+
+ // If the left child is not null
+ if(currVal != "N") {
+
+ // Create the left child for the current node
+ currNode->left = newNode(stoi(currVal));
+
+ // Push it to the queue
+ queue.push(currNode->left);
+ }
+
+ // For the right child
+ i++;
+ if(i >= ip.size())
+ break;
+ currVal = ip[i];
+
+ // If the right child is not null
+ if(currVal != "N") {
+
+ // Create the right child for the current node
+ currNode->right = newNode(stoi(currVal));
+
+ // Push it to the queue
+ queue.push(currNode->right);
+ }
+ i++;
+ }
+
+ return root;
+}
+
+
+
+int main() {
+ int t;
+ string tc;
+ getline(cin, tc);
+ t=stoi(tc);
+ while(t--)
+ {
+ string s ,ch;
+ getline(cin, s);
+ Node* root = buildTree(s);
+
+ vector diagonalNode = diagonal(root);
+ for(int i = 0;i>&m,int d)
+{
+ if(!root)
+ return;
+ m[d].push_back(root->data);
+ preorder(root->left,m,d+1);
+ preorder(root->right,m,d);
+}
+vector diagonal(Node *root)
+{
+ vectorv;
+ int d=0;
+ map>m;
+ preorder(root,m,d);
+ for(auto x:m)
+ {
+ for(auto y:x.second)
+ {
+ v.push_back(y);
+ }
+ }
+ return v;
+}
diff --git a/CPP/Data Structures/Trees/Binary Trees/Lowest Common Ancestor of Deepest Leaves.cpp b/CPP/Data Structures/Trees/Binary Trees/Lowest Common Ancestor of Deepest Leaves.cpp
new file mode 100644
index 000000000..c18843e97
--- /dev/null
+++ b/CPP/Data Structures/Trees/Binary Trees/Lowest Common Ancestor of Deepest Leaves.cpp
@@ -0,0 +1,73 @@
+/*Given the root of a binary tree, return the
+lowest common ancestor of its deepest leaves.*/
+
+//Input:-
+
+/* 0
+ / \
+ 1 3
+ \
+ 2
+*/
+
+//Output:- 2
+
+/*Explanation:- The deepest leaf node in the tree is 2,
+ the lca of one node is itself.*/
+#include
+using namespace std;
+
+ // Definition for a binary tree node.
+
+ struct TreeNode {
+ int val;
+ TreeNode *left;
+ TreeNode *right;
+ TreeNode() : val(0), left(nullptr), right(nullptr) {}
+ TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}
+ TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}
+ };
+class Solution {
+public:
+ pair solve(TreeNode* root){
+ if(root==NULL){
+ return {root,0};
+ }
+ auto l=solve(root->left);
+ auto r=solve(root->right);
+ //if the left level == right level then the lca is itself, as it is the deepest level.
+ if(l.second==r.second){
+ return {root,l.second+1};
+ }
+ //if left level is greater then left child is the lca
+ //vice-versa
+ if(l.second>r.second){
+ return {l.first,l.second+1};
+ }
+ return {r.first,r.second+1};
+ }
+ TreeNode* lcaDeepestLeaves(TreeNode* root) {
+ return solve(root).first;
+ }
+};
+//Printing in preorder
+void preorder(TreeNode* root){
+ if(root==NULL){
+ return ;
+ }
+ cout<val<<" ";
+ preorder(root->left);
+ preorder(root->right);
+
+}
+int main(){
+ struct TreeNode* root=new TreeNode(0);
+ root->left=new TreeNode(1);
+ root->right=new TreeNode(3);
+ root->left->right=new TreeNode(2);
+ Solution obj;
+ struct TreeNode* node=obj.lcaDeepestLeaves(root);
+ preorder(node);
+ return 0;
+}
+
diff --git a/CPP/Data Structures/Trees/Binary Trees/TreeTraversal.cpp b/CPP/Data Structures/Trees/Binary Trees/TreeTraversal.cpp
new file mode 100644
index 000000000..cf3a198b6
--- /dev/null
+++ b/CPP/Data Structures/Trees/Binary Trees/TreeTraversal.cpp
@@ -0,0 +1,76 @@
+//TREE TRAVERSAL
+#include
+#include
+using namespace std;
+struct node{
+ int data;
+ node* left;
+ node* right;
+};
+
+node* newNode(int key)
+{
+ node* tmp = new node();
+ tmp->data = key;
+ tmp->left = tmp->right = nullptr;
+
+ return tmp;
+}
+
+//INSERTION
+node* insert(node* root, int l_data){
+ if(root == nullptr){
+ return newNode(l_data);
+ }
+ if(l_data <= root->data){
+ root->left = insert(root->left, l_data);
+ }else{
+ root->right = insert(root->right, l_data);
+ }
+ return root;
+}
+
+//INORDER TRAVERSAL
+void inorder(node* root){
+ if(root == nullptr){
+ return;
+ }
+ inorder(root->left);
+ cout<data<<" ";
+ inorder(root->right);
+}
+
+//PREORDER TRAVERSAL
+void preOrder(node* root){
+ if(root == nullptr){
+ return;
+ }
+ cout<data<<" ";
+ preOrder(root->left);
+ preOrder(root->right);
+}
+
+//POSTORDER TRAVERSAL
+void postOrder(node* root){
+ if(root == nullptr){
+ return;
+ }
+ postOrder(root->left);
+ postOrder(root->right);
+ cout<data<<" ";
+}
+
+int main(){
+ node *root = newNode(1);
+
+ root->left = newNode(2);
+ root->right = newNode(3);
+ root->left->left = newNode(4);
+ root->left->right = newNode(5);
+ cout<<"\n Pre order transversal: ";
+ preOrder(root);
+ cout<<"\n Inorder transversal: ";
+ inorder(root);
+ cout<<"\n Post order transversal: ";
+ postOrder(root);
+}
diff --git a/CPP/Data Structures/Trees/Binary Trees/binaryTreeNode.h b/CPP/Data Structures/Trees/Binary Trees/binaryTreeNode.h
new file mode 100644
index 000000000..02443dad8
--- /dev/null
+++ b/CPP/Data Structures/Trees/Binary Trees/binaryTreeNode.h
@@ -0,0 +1,17 @@
+template
+class binarynode {
+ public:
+ t data;
+ binarynode * left;
+ binarynode * right;
+
+ binarynode(t data){
+ this -> data = data;
+ left = right = NULL;
+ }
+ ~binarynode(){
+ delete left;
+ delete right;
+ }
+
+};
\ No newline at end of file
diff --git a/CPP/Data Structures/Trees/Binary Trees/binaryTress.cpp b/CPP/Data Structures/Trees/Binary Trees/binaryTress.cpp
new file mode 100644
index 000000000..cf2ce5a1c
--- /dev/null
+++ b/CPP/Data Structures/Trees/Binary Trees/binaryTress.cpp
@@ -0,0 +1,62 @@
+#include
+using namespace std;
+#include
+#include
+#include "binaryTreeNode.h"
+
+binarynode * takeInput(){ // level wise input
+ cout << "Enter the root data : ";
+ int rootData;
+ cin >> rootData;
+ binarynode * root = new binarynode(rootData);
+ queue *> q1;
+ q1.push(root);
+ while(q1.size() != 0){
+ binarynode * front = q1.front();
+ q1.pop();
+ cout << "Enter the left child of " << front -> data << " : ";
+ cin >> rootData;
+ binarynode * leftChild = (rootData != -1) ? new binarynode(rootData) : NULL;
+ cout << "Enter the right child of " << front -> data << " : ";
+ cin >> rootData;
+ binarynode * rightChild = (rootData != -1) ? new binarynode(rootData) : NULL;
+ front -> left = leftChild;
+ front -> right = rightChild;
+ if (leftChild != NULL) q1.push(leftChild);
+ if (rightChild !=NULL) q1.push(rightChild);
+ }
+ return root;
+}
+
+void printTree(binarynode * root){
+ if (root == NULL) return;
+ cout << root -> data << " : ";
+ if (root -> left != NULL){
+ cout << "L " << root -> left -> data << " , ";
+ }
+ if (root -> right != NULL){
+ cout << "R " < right -> data << " ";
+ }
+ cout << endl;
+ printTree(root -> left);
+ printTree(root -> right);
+}
+
+int height(binarynode * root){ // cn way, better way infact the best way
+ if (root == NULL) return 0;
+ return 1 + max(height(root -> left), height(root -> right));
+}
+
+int countNoOfNodes(binarynode * root){ // well done
+ if (root == NULL) return 0;
+ int count = 1; // on account of root node
+ count += countNoOfNodes(root -> left) + countNoOfNodes(root -> right);
+ return count;
+}
+
+int main (){
+ binarynode * root = takeInput();
+ printTree(root);
+ cout << "Height of the tree is : " << height(root);
+ return 0;
+}
\ No newline at end of file
diff --git a/CPP/Data Structures/Trees/Binary Trees/find_diameter_binary_trees.cpp b/CPP/Data Structures/Trees/Binary Trees/find_diameter_binary_trees.cpp
new file mode 100644
index 000000000..86e91a8a9
--- /dev/null
+++ b/CPP/Data Structures/Trees/Binary Trees/find_diameter_binary_trees.cpp
@@ -0,0 +1,58 @@
+// C++ program to find the diameter of a Binary Tree
+#include
+using namespace std;
+
+struct node {
+ int data;
+ struct node *left, *right;
+};
+
+struct node* newNode(int data);
+
+int diameterOpt(struct node* root, int* height)
+{
+ int lh = 0, rh = 0;
+
+ int ldiameter = 0, rdiameter = 0;
+
+ if (root == NULL) {
+ *height = 0;
+ return 0;
+ }
+
+ ldiameter = diameterOpt(root->left, &lh);
+ rdiameter = diameterOpt(root->right, &rh);
+
+ *height = max(lh, rh) + 1;
+
+ return max(lh + rh + 1, max(ldiameter, rdiameter));
+}
+
+struct node* newNode(int data)
+{
+ struct node* node
+ = (struct node*)malloc(sizeof(struct node));
+ node->data = data;
+ node->left = NULL;
+ node->right = NULL;
+
+ return (node);
+}
+
+// Driver Code
+int main()
+{
+
+ struct node* root = newNode(1);
+ root->left = newNode(2);
+ root->right = newNode(3);
+ root->left->left = newNode(4);
+ root->left->right = newNode(5);
+
+ int height = 0;
+ cout << "Diameter of the given binary tree is " << diameterOpt(root, &height);
+
+ return 0;
+}
+
+
diff --git a/CPP/Data Structures/Trees/Binary Trees/is-balanced-binary-tree b/CPP/Data Structures/Trees/Binary Trees/is-balanced-binary-tree
new file mode 100644
index 000000000..641f2f8a5
--- /dev/null
+++ b/CPP/Data Structures/Trees/Binary Trees/is-balanced-binary-tree
@@ -0,0 +1,110 @@
+#include
+using namespace std;
+
+class node
+{
+public:
+ int data;
+ node *left;
+ node *right;
+
+ node(int d)
+ {
+ data = d;
+ left = right = NULL;
+ }
+};
+
+node *CreateTree()
+{
+ string v;
+ cin >> v;
+
+ if (v == "n")
+ {
+ return NULL;
+ }
+
+ int w=stoi(v);
+ node *root = new node(w);
+ root->left = CreateTree();
+ root->right = CreateTree();
+ return root;
+}
+
+
+
+ void display(node *root) {
+ if(root==NULL)
+ {
+ return;
+ }
+
+ string str = "";
+ str += (root->left) == NULL ? "." : to_string(root->left->data) + "";
+ str += " <- " + to_string(root->data) + " -> ";
+ str += (root->right) == NULL ? "." : to_string(root->right->data) + "";
+ cout<left);
+ display(root->right);
+ }
+
+ int height(node *root) {
+ if(root == NULL){
+ return -1;
+ }
+
+ int lh = height(root->left);
+ int rh = height(root->right);
+ int th = max(lh, rh) + 1;
+ return th;
+ }
+
+bool isBalanced(node* root, int* height)
+{
+
+ /* lh --> Height of left subtree
+ rh --> Height of right subtree */
+ int lh = 0, rh = 0;
+
+ /* l will be true if left subtree is balanced
+ and r will be true if right subtree is balanced */
+ int l = 0, r = 0;
+
+ if (root == NULL) {
+ *height = 0;
+ return 1;
+ }
+
+ /* Get the heights of left and right subtrees in lh and rh
+ And store the returned values in l and r */
+ l = isBalanced(root->left, &lh);
+ r = isBalanced(root->right, &rh);
+
+ /* Height of current node is max of heights of left and
+ right subtrees plus 1*/
+ *height = (lh > rh ? lh : rh) + 1;
+
+ /* If difference between heights of left and right
+ subtrees is more than 2 then this node is not balanced
+ so return 0 */
+ if (abs(lh - rh) >= 2)
+ return 0;
+
+ /* If this node is balanced and left and right subtrees
+ are balanced then return true */
+ else
+ return l && r;
+}
+
+int main()
+{
+ int p;cin>>p;
+ node *root = CreateTree();
+ int height = 0;
+ if (isBalanced(root,&height))
+ cout << "true";
+ else
+ cout << "false";
+}
diff --git a/CPP/Data Structures/Trees/Binary Trees/levelorder-binarytree b/CPP/Data Structures/Trees/Binary Trees/levelorder-binarytree
new file mode 100644
index 000000000..f049eeb6d
--- /dev/null
+++ b/CPP/Data Structures/Trees/Binary Trees/levelorder-binarytree
@@ -0,0 +1,68 @@
+#include
+using namespace std;
+
+class node
+{
+public:
+ int data;
+ node *left;
+ node *right;
+
+ node(int d)
+ {
+ data = d;
+ left = right = NULL;
+ }
+};
+
+node *CreateTree()
+{
+ string v;
+ cin >> v;
+
+ if (v == "n")
+ {
+ return NULL;
+ }
+
+ int w=stoi(v);
+ node *root = new node(w);
+ root->left = CreateTree();
+ root->right = CreateTree();
+ return root;
+}
+
+void levelorder(node *root)
+{
+ queue mq;
+ mq.push(root);
+
+ while(mq.size()>0)
+ {
+ int cicl=mq.size();
+
+ for(int i=0;idata<<" ";
+
+ if(root->left != NULL){
+ mq.push(root->left);
+ }
+
+ if(root->right != NULL){
+ mq.push(root->right);
+ }
+ }
+ cout<>p;
+ node *root = CreateTree();
+ levelorder(root);
+ return 0;
+}
diff --git a/CPP/Data Structures/Trees/Binary Trees/maximum_depth_Binarytree.cpp b/CPP/Data Structures/Trees/Binary Trees/maximum_depth_Binarytree.cpp
new file mode 100644
index 000000000..d58c85076
--- /dev/null
+++ b/CPP/Data Structures/Trees/Binary Trees/maximum_depth_Binarytree.cpp
@@ -0,0 +1,21 @@
+/**
+ * Definition for a binary tree node.
+ * struct TreeNode {
+ * int val;
+ * TreeNode *left;
+ * TreeNode *right;
+ * TreeNode() : val(0), left(nullptr), right(nullptr) {}
+ * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}
+ * TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}
+ * };
+ */
+
+class Solution {
+public:
+ int cnt=0;
+ int maxDepth(TreeNode* root) {
+ if(!root) return 0;
+ return max(maxDepth(root->left),maxDepth(root->right))+1;
+
+ }
+};
diff --git a/CPP/Data Structures/Trees/Generic Trees/are-generic-trees-similar b/CPP/Data Structures/Trees/Generic Trees/are-generic-trees-similar
new file mode 100644
index 000000000..3d41d9c60
--- /dev/null
+++ b/CPP/Data Structures/Trees/Generic Trees/are-generic-trees-similar
@@ -0,0 +1,149 @@
+#include
+#include
+#include
+
+using namespace std;
+
+struct Node
+{
+ int data;
+ vector children;
+};
+
+Node *construct(int arr[], int n)
+{
+ Node *root = NULL;
+ stack st;
+ for (int i = 0; i < n; i++)
+ {
+ if (arr[i] == -1)
+ {
+ if (st.size() != 0)
+ st.pop();
+ }
+ else
+ {
+ Node *t = new Node();
+ t->data = arr[i];
+
+ if (st.size() > 0)
+ {
+ Node *top = st.top();
+ top->children.push_back(t);
+ }
+
+ else
+ {
+ root = t;
+ }
+ st.push(t);
+ }
+ }
+ return root;
+};
+
+int size(Node *node)
+{
+ int s = 0;
+
+ for (int i = 0; i < node->children.size(); i++)
+ {
+ s += size(node->children[i]);
+ }
+ s += 1;
+
+ return s;
+}
+
+vector galvin(Node *root, int b){
+ if(root->data == b){
+ vector path;
+ path.push_back(root->data);
+ return path;
+ }
+
+ for(Node *child: root->children){
+ vector ptc = galvin(child, b);
+ if(ptc.size() > 0){
+ ptc.push_back(root->data);
+ return ptc;
+ }
+ }
+ return vector();
+
+
+ }
+
+ int distanceBetweenNodes(Node *root, int d1, int d2){
+ vector p1=galvin(root, d1);
+ vector p2=galvin(root, d2);
+
+ int i = p1.size() - 1;
+ int j = p2.size() - 1;
+
+ while(i >= 0 && j >= 0 && p1[i] == p2[j]){
+ i--;
+ j--;
+ }
+
+
+ return i+1 + j+1;
+ }
+
+
+ bool areSimilar(Node *root,Node *node)
+ {
+ if(root->children.size()!=node->children.size())
+ return false;
+
+ for (int i = 0; i < node->children.size() ; i++) {
+ Node *c1 = root->children[i];
+ Node *c2 = node->children[i];
+ if (areSimilar(c1, c2) == false) {
+ return false;
+ }
+ }
+
+ return true;
+ }
+
+
+void display(Node *root)
+{
+ if(root == NULL)return;
+ string str = to_string(root->data) + "->";
+ for (Node* child : root->children)
+ {
+ str +=to_string(child->data) + ",";
+ }
+ str += ".";
+ //cout << (str) << endl;
+
+ // for (Node * child : root->children)
+ // {
+ // display(child);
+ // }
+}
+
+int main()
+{
+ int n;
+ cin >> n;
+ int arr[n];
+ for (int i = 0; i < n; i++)
+ cin >> arr[i];
+
+ int m;cin>>m;
+ int brr[m];
+ for (int i = 0; i < m; i++)
+ cin >> brr[i];
+
+ Node *root = construct(arr, n);
+ Node *node = construct(brr,m);
+ bool a = areSimilar(root,node);
+ if(a==1)
+ cout<<"true"<
+#include
+#include
+
+using namespace std;
+
+struct Node
+{
+ int data;
+ vector children;
+};
+
+Node *construct(int arr[], int n)
+{
+ Node *root = NULL;
+ stack st;
+ for (int i = 0; i < n; i++)
+ {
+ if (arr[i] == -1)
+ {
+ if (st.size() != 0)
+ st.pop();
+ }
+ else
+ {
+ Node *t = new Node();
+ t->data = arr[i];
+
+ if (st.size() > 0)
+ {
+ Node *top = st.top();
+ top->children.push_back(t);
+ }
+
+ else
+ {
+ root = t;
+ }
+ st.push(t);
+ }
+ }
+ return root;
+};
+
+int size(Node *node)
+{
+ int s = 0;
+
+ for (int i = 0; i < node->children.size(); i++)
+ {
+ s += size(node->children[i]);
+ }
+ s += 1;
+
+ return s;
+}
+
+vector galvin(Node *root, int b){
+ if(root->data == b){
+ vector path;
+ path.push_back(root->data);
+ return path;
+ }
+
+ for(Node *child: root->children){
+ vector ptc = galvin(child, b);
+ if(ptc.size() > 0){
+ ptc.push_back(root->data);
+ return ptc;
+ }
+ }
+ return vector();
+
+
+ }
+
+ int distanceBetweenNodes(Node *root, int d1, int d2){
+ vector p1=galvin(root, d1);
+ vector p2=galvin(root, d2);
+
+ int i = p1.size() - 1;
+ int j = p2.size() - 1;
+
+ while(i >= 0 && j >= 0 && p1[i] == p2[j]){
+ i--;
+ j--;
+ }
+
+
+ return i+1 + j+1;
+ }
+
+
+ bool areSimilar(Node *root,Node *node)
+ {
+ if(root->children.size()!=node->children.size())
+ return false;
+
+ for (int i = 0; i < node->children.size() ; i++) {
+ Node *c1 = root->children[i];
+ Node *c2 = node->children[i];
+ if (areSimilar(c1, c2) == false) {
+ return false;
+ }
+ }
+
+ return true;
+ }
+
+
+void display(Node *root)
+{
+ if(root == NULL)return;
+ string str = to_string(root->data) + "->";
+ for (Node* child : root->children)
+ {
+ str +=to_string(child->data) + ",";
+ }
+ str += ".";
+ //cout << (str) << endl;
+
+ // for (Node * child : root->children)
+ // {
+ // display(child);
+ // }
+}
+
+
+static int dia=0;
+
+int diameter(Node *root)
+{
+ int ht=-1;
+ int sh=-1;
+
+ for (Node *child : root->children) {
+ int ch = diameter(child);
+ if (ch >= ht) {
+ sh = ht;
+ ht = ch;
+ } else if (ch >= sh) {
+ sh = ch;
+ }
+ }
+
+ if (sh + ht + 2 > dia) {
+ dia = sh + ht + 2;
+ }
+
+ ht += 1;
+ return ht;
+
+
+}
+
+
+int main()
+{
+ int n;
+ cin >> n;
+ int arr[n];
+ for (int i = 0; i < n; i++)
+ cin >> arr[i];
+ Node *root = construct(arr, n);
+ dia = 0;
+ diameter(root);
+ cout<
+#include "treenode.h"
+#include
+using namespace std;
+
+treenode * takeInput(){ // level wise input
+ int rootData;
+ cout << "Enter The Data of the Root Element : ";
+ cin >> rootData;
+ treenode * root = new treenode (rootData);
+ queue *> q1;
+ q1.push(root);
+ while(q1.size() != 0){
+ treenode* front = q1.front();
+ q1.pop();
+ int noOfChildren;
+ cout << "Enter the no of children of "<< front -> data << " : ";
+ cin >> noOfChildren;
+ for (int i =0;idata << " : ";
+ cin >> nodeData;
+ treenode * newNode = new treenode(nodeData);
+ front -> children.push_back(newNode);
+ q1.push(newNode);
+ }
+ }
+ return root;
+}
+
+void printTree(treenode * root){
+ if (root == NULL){
+ return;
+ }
+ cout << root -> data << " : ";
+ for (int i =0;i children.size();i++){
+ cout << root -> children[i]->data << " , ";
+ }
+ cout << endl;
+ for (int i =0;i children.size() ; i++){
+ printTree(root -> children[i]);
+ }
+}
+
+int noOFNodes(treenode * root){
+ int sum = 1; // on account of the root node
+ for (int i =0;i children.size();i++){
+ sum += noOFNodes(root -> children[i]);
+ }
+ return sum;
+}
+
+int main(){
+ treenode * root = takeInput();
+ printTree(root);
+ cout << "The no of nodes are : " << noOFNodes(root);
+ return 0;
+}
\ No newline at end of file
diff --git a/CPP/Data Structures/Trees/Generic Trees/treenode.h b/CPP/Data Structures/Trees/Generic Trees/treenode.h
new file mode 100644
index 000000000..a444d0cf2
--- /dev/null
+++ b/CPP/Data Structures/Trees/Generic Trees/treenode.h
@@ -0,0 +1,19 @@
+#include
+using namespace std;
+
+template