<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>Forem: vinay</title>
    <description>The latest articles on Forem by vinay (@vinaygo).</description>
    <link>https://forem.com/vinaygo</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F896077%2F9c0f3a0e-e677-49ef-a22d-b66674d22c07.png</url>
      <title>Forem: vinay</title>
      <link>https://forem.com/vinaygo</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/vinaygo"/>
    <language>en</language>
    <item>
      <title>Concurrency Merge Sort Using Channels and Goroutines in Golang</title>
      <dc:creator>vinay</dc:creator>
      <pubDate>Sat, 11 Feb 2023 10:39:21 +0000</pubDate>
      <link>https://forem.com/vinaygo/concurrency-merge-sort-using-channels-and-goroutines-in-golang-35f7</link>
      <guid>https://forem.com/vinaygo/concurrency-merge-sort-using-channels-and-goroutines-in-golang-35f7</guid>
      <description>&lt;p&gt;Merge sort is a divide and conquer algorithm used to sort a list of elements. The algorithm starts by dividing the unsorted list into n sublists, each containing one element. The sublists are then merged in a manner that results in a sorted list. The merging process involves comparing the elements of the sublists and arranging them in the correct order. The time complexity of merge sort is O(n log n), making it an efficient sorting algorithm for large lists.&lt;br&gt;
Optimize sorting with concurrent Merge Sort using channels and goroutines in Go.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;func Mergech(left chan int, right chan int, c chan int) {
    defer close(c)
    val, ok := &amp;lt;-left
    val2, ok2 := &amp;lt;-right
    for ok &amp;amp;&amp;amp; ok2 {
        if val &amp;lt; val2 {
            c &amp;lt;- val
            val, ok = &amp;lt;-left
        } else {
            c &amp;lt;- val2
            val2, ok2 = &amp;lt;-right
        }
    }
    for ok {
        c &amp;lt;- val
        val, ok = &amp;lt;-left
    }
    for ok2 {
        c &amp;lt;- val2
        val2, ok2 = &amp;lt;-right
    }
}
func MergeSort(arr []int, ch chan int) {
    if len(arr) &amp;lt; 2 {
        ch &amp;lt;- arr[0]
        defer close(ch)
        return
    }
    left := make(chan int)
    right := make(chan int)
    go MergeSort(arr[len(arr)/2:], left)
    go MergeSort(arr[:len(arr)/2], right)
    go Mergech(left, right, ch)
}
func main() {
    a := []int{5,4,3,2,1}
    c := make(chan int)
    var wg sync.WaitGroup
    wg.Add(1)
    go func() {
        defer wg.Done()
        mergeSort(a, c)
    }()
    wg.Wait()
    var s []int
    for v := range c {
        s = append(s, v)
    }
    fmt.Println(s)
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
      <category>go</category>
      <category>concurrency</category>
      <category>golan</category>
      <category>beginners</category>
    </item>
    <item>
      <title>How to remove a specific character from the string in Golang?</title>
      <dc:creator>vinay</dc:creator>
      <pubDate>Thu, 01 Dec 2022 04:54:14 +0000</pubDate>
      <link>https://forem.com/vinaygo/how-to-remove-a-specific-character-from-the-string-in-golang-56in</link>
      <guid>https://forem.com/vinaygo/how-to-remove-a-specific-character-from-the-string-in-golang-56in</guid>
      <description>&lt;p&gt;note:&lt;br&gt;
1:This removes bytes from strings. If your string has characters that are encoded as multiple bytes in UTF-8, then slicing single bytes out will produce undesired results. Let us know if you need to support that.&lt;br&gt;
2:If you need to remove multiple bytes at multiple indexes, there is a more efficient way to do that, too!&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;package main

import (
    "fmt"
)

func strRemoveAt(s string, index, length int) string {
    return s[:index] + s[index+length:]
}

func main() {
        result:=strRemoveAt("charliec", 0, 1)
        fmt.Println(result)
}

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
      <category>cpp</category>
      <category>java</category>
      <category>programming</category>
    </item>
    <item>
      <title>Polymorphism in Golang</title>
      <dc:creator>vinay</dc:creator>
      <pubDate>Tue, 15 Nov 2022 02:59:31 +0000</pubDate>
      <link>https://forem.com/vinaygo/polymorphism-in-golang-ii</link>
      <guid>https://forem.com/vinaygo/polymorphism-in-golang-ii</guid>
      <description>&lt;p&gt;1.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;package main

import "fmt"

//creating class
type PersonClass struct {
    name  string
    age   string
    color string
}

//person one have class properties and function
type Person1 interface {
    Walking() string
    Runnig() string
}

//person two have class properties and Person1 function and extra function
type Person2 interface {
    Person1
    Sleping() string
    Dringking() string
}

//
//person tree have class properties and Person1 function and Person2 ,extra function
type Person3 interface {
    Person2
    Learing() string
}

func (p PersonClass) Walking() string {
    return "walking :" + p.name
}
func (p PersonClass) Runnig() string {
    return "runnig :" + p.name
}

func (p PersonClass) Sleping() string {
    return "Im sleping :" + p.name
}
func (p PersonClass) Dringking() string {
    return "Im drinking :" + p.name
}

func (p PersonClass) Learing() string {
    return "Learing :" + p.name
}

func main() {

    w := []Person1{
        PersonClass{"mr.Boom", "24", "Oraange"},
    }

    x := []Person2{
        PersonClass{"mr.Hello", "22", "brown"},
    }
    p := []Person3{
        PersonClass{"mr.kk", "21", "red"},
    }
    fmt.Println("Person 1")
    for _, v := range w {
        fmt.Println(v.Runnig(), v.Walking())
    }
    fmt.Println("Person 2")

    for _, v := range x {
        fmt.Println(v.Dringking(), v.Runnig(), v.Sleping(), v.Walking())
    }
    fmt.Println("Person 3")
    for _, v := range p {
        fmt.Println(v.Walking(), v.Runnig(), v.Dringking(), v.Sleping(), v.Learing())
    }
}

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
      <category>go</category>
    </item>
    <item>
      <title>How to insert element at any position in Slice Golang</title>
      <dc:creator>vinay</dc:creator>
      <pubDate>Fri, 11 Nov 2022 05:09:01 +0000</pubDate>
      <link>https://forem.com/vinaygo/how-to-insert-element-at-any-position-in-slice-golang-28b1</link>
      <guid>https://forem.com/vinaygo/how-to-insert-element-at-any-position-in-slice-golang-28b1</guid>
      <description>&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;func Insert(array []int, element int, i int) []int {
    return append(array[:i], append([]int{element}, array[i:]...)...)
}
func main() {
    a := []int{10, 20, 30, 40}
    a = Insert(a, 30, len(a))
    fmt.Println(a)
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
      <category>go</category>
    </item>
    <item>
      <title>Golang TwoSum</title>
      <dc:creator>vinay</dc:creator>
      <pubDate>Wed, 26 Oct 2022 07:49:49 +0000</pubDate>
      <link>https://forem.com/vinaygo/golang-twosum-3ldm</link>
      <guid>https://forem.com/vinaygo/golang-twosum-3ldm</guid>
      <description>&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;package main

import (
    "bufio"
    "fmt"
    "log"
    "os"
    "strconv"
    "strings"
)

func BruteForce(nums []int, target int) []int {
    IntSlice := new([]int)
    // using linear search chek
    for index1, Num1 := range nums {
        for index2, Num2 := range nums {
            //if both the number add == target and index not same then append to IntSlice
            if Num1+Num2 == target &amp;amp;&amp;amp; index1 != index2 {
                *IntSlice = append(*IntSlice, index1)
            }
        }
    }
    return *IntSlice
}
func HashMap(nums []int, target int) []int {
    //Hashmap store the complement and index
    //3,2,3 --&amp;gt;6
    see := make(map[int]int)
    //map[]

    //result
    IntSlice := new([]int)
    //chek the complement if true append both index to IntSlice if not update to Hashmap
    for Cindex := 0; Cindex &amp;lt; len(nums); Cindex++ {
        // 3:=6-3
        r := target - nums[Cindex]
        //val,bool:=map[key]
        index, ok := see[r]
        if ok {
            *IntSlice = append(*IntSlice, index, Cindex)
            //0,2
        }
        //update to Hashmap
        //complement=index
        //
        //map[3:0,2:1,]
        see[nums[Cindex]] = Cindex
    }
    return *IntSlice

}

func main() {
    reader := bufio.NewReader(os.Stdin)
    //using reader read the input by using readline
    fmt.Print("Please enter your Slice Numbers: ")
    //example:
    //Please enter your Slice Numbers:2 7 11 6
    val, _, _ := reader.ReadLine()
    //ReadLine return byte,bool,error

    //convert byte to string
    Readline := strings.TrimSpace(string(val))

    //split convert string to slice_string
    input1 := strings.Split(Readline, " ")
    var a []int
    for i := 0; i &amp;lt; len(input1); i++ {
        intnum, err := strconv.Atoi(input1[i])
        if err != nil {
            log.Fatal(err)
        }
        a = append(a, intnum)
    }

    //convert byte to string
    fmt.Print("Please enter your target Number : ")
    var w int
    fmt.Scanln(&amp;amp;w)
    output := HashMap(a, w)
    fmt.Println("Hash map Two Sum is :", output)
    output2 := BruteForce(a, w)
    fmt.Println("Bruit_Force Two Sum is :", output2)

}

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;unit test of about code&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;package main

import (
    "reflect"
    "testing"
)

func TestHashMap(t *testing.T) {
    type args struct {
        nums   []int
        target int
    }
    tests := []struct {
        name string
        args args
        want []int
    }{
        {
            name: "CHEk",
            args: args{
                nums:   []int{2, 7, 11, 15},
                target: 9,
            },
            want: []int{0, 1},
        }, {
            name: "CHEk",
            args: args{
                nums:   []int{3, 2, 4},
                target: 6,
            },
            want: []int{1, 2},
        }, {
            name: "CHEk",
            args: args{
                nums:   []int{3, 3},
                target: 6,
            },
            want: []int{0, 1},
        },
    }
    for _, tt := range tests {
        t.Run(tt.name, func(t *testing.T) {
            if got := HashMap(tt.args.nums, tt.args.target); !reflect.DeepEqual(got, tt.want) {
                t.Errorf("HashMap() = %v, want %v", got, tt.want)
            }
        })
    }
}

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
    </item>
    <item>
      <title>How to generate golang unit test code in VS code</title>
      <dc:creator>vinay</dc:creator>
      <pubDate>Fri, 21 Oct 2022 05:59:25 +0000</pubDate>
      <link>https://forem.com/vinaygo/how-to-generate-golang-unit-test-code-in-vs-code-2o9a</link>
      <guid>https://forem.com/vinaygo/how-to-generate-golang-unit-test-code-in-vs-code-2o9a</guid>
      <description>&lt;ol&gt;
&lt;li&gt;Go for Function name ---&amp;gt;right click and in that we have so many option---&amp;gt;select --go: generate unit test for function&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;main.go&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;package main

import "fmt"

func Add(a int, b int) int {
    return a + b
}

func main() {
    b := Add(10, 20)
    fmt.Println(b)

}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;main_test.go&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;package main

import "testing"

func TestAdd(t *testing.T) {
    type args struct {
        a int
        b int
    }
    tests := []struct {
        name string
        args args
        want int
    }{
        {
            name: "hello",
            args: args{
                a: 1,
                b: 2,
            },
            want: 3,
        },
    }
    for _, tt := range tests {
        t.Run(tt.name, func(t *testing.T) {
            if got := Add(tt.args.a, tt.args.b); got != tt.want {
                t.Errorf("Add() = %v, want %v", got, tt.want)
            }
        })
    }
}

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
      <category>go</category>
    </item>
    <item>
      <title>How to Delete Duplicate Numbers in Golang</title>
      <dc:creator>vinay</dc:creator>
      <pubDate>Thu, 20 Oct 2022 14:01:01 +0000</pubDate>
      <link>https://forem.com/vinaygo/how-to-delete-duplicate-numbers-in-golang-33dk</link>
      <guid>https://forem.com/vinaygo/how-to-delete-duplicate-numbers-in-golang-33dk</guid>
      <description>&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;func Set(arr []int) []int {
    for i := 0; i &amp;lt; len(arr); i++ {
        for j := 0; j &amp;lt; len(arr); j++ {
            if arr[i] == arr[j] &amp;amp;&amp;amp; i != j {
                arr = append(arr[:j],arr[j+1:]...)
            }
        }
    }
    return arr
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
      <category>go</category>
    </item>
    <item>
      <title>how to delete the Element in slice using Slice Golang</title>
      <dc:creator>vinay</dc:creator>
      <pubDate>Thu, 20 Oct 2022 13:38:32 +0000</pubDate>
      <link>https://forem.com/vinaygo/how-to-delete-the-element-in-slice-using-slice-golang-3316</link>
      <guid>https://forem.com/vinaygo/how-to-delete-the-element-in-slice-using-slice-golang-3316</guid>
      <description>&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;//how to delete the Number in Slice Golang
    a := []int{10, 20, 30, 40, 50, 60, 70, 80, 90}
    var i int
    fmt.Print("Enter deleted number index..: ")
    fmt.Scan(&amp;amp;i)
    a = append(a[:i], a[i+1:]...)
    fmt.Println(a)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
      <category>go</category>
    </item>
    <item>
      <title>Singly ,Doubly ,Circular Linked List in golang....</title>
      <dc:creator>vinay</dc:creator>
      <pubDate>Fri, 16 Sep 2022 10:18:01 +0000</pubDate>
      <link>https://forem.com/vinaygo/singly-doubly-circular-linked-list-in-golang-490a</link>
      <guid>https://forem.com/vinaygo/singly-doubly-circular-linked-list-in-golang-490a</guid>
      <description>&lt;p&gt;**Types of Linked List - Singly linked, doubly linked and circular&lt;br&gt;
In this tutorial, you will learn different types of linked list. Also, you will find implementation of linked list in golang.&lt;/p&gt;

&lt;p&gt;Before you learn about the type of the linked list, make sure you know about the LinkedList Data Structure.&lt;/p&gt;

&lt;p&gt;There are three common types of Linked List.&lt;/p&gt;

&lt;p&gt;Singly Linked List&lt;br&gt;
Doubly Linked List&lt;br&gt;
Circular Linked List&lt;br&gt;
**_&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;**Singly Linked List in golang**
package main

import (
    "fmt"
    "sort"
)

type Node struct {
    data int
    next *Node
}

type Slink struct {
    head *Node
    tail *Node
}

func (l *Slink) append(n int) {
    newNode := &amp;amp;Node{data: n}
    if l.head == nil {
        l.head = newNode
    } else {
        l.tail.next = newNode
    }
    l.tail = newNode
}

func (l *Slink) push(n int, pos int) {
    if pos == 0 {
        newNode := &amp;amp;Node{data: n}
        newNode.next = l.head
        l.head = newNode
    } else if pos &amp;gt; 0 &amp;amp;&amp;amp; pos &amp;lt; l.len() {
        newNode := &amp;amp;Node{data: n}
        p := l.head
        i := 0
        for i &amp;lt; pos-1 {
            p = p.next
            i += 1
        }
        newNode.next = p.next
        p.next = newNode
    } else {
        newNode := &amp;amp;Node{data: n}
        l.tail.next = newNode
        l.tail = newNode
    }

}
func (l *Slink) len() int {
    p := l.head
    count := 0
    for p != nil {
        p = p.next
        count++
    }
    return count

}

func (l *Slink) pop(pos int) int {
    b := 0
    if pos == 0 {
        temp := l.head
        l.head = l.head.next
        b = temp.data
        temp.next = nil
    } else if pos &amp;gt; 0 &amp;amp;&amp;amp; pos &amp;lt; l.len()-1 {
        p := l.head
        i := 0
        for i &amp;lt; pos-1 {
            p = p.next
            i += 1
        }
        temp := p.next
        p.next = p.next.next
        b = temp.data
        temp.next = nil
    } else {
        p := l.head
        for p.next != l.tail {
            p = p.next
        }
        b = p.next.data
        l.tail = p
        p.next = nil
    }
    return b
}

func (l *Slink) Reverse() *Node {
    var prev *Node
    currNode := l.head
    nextNode := l.head
    for nextNode != l.tail {
        prev = currNode
        nextNode = nextNode.next
        currNode.next = prev
        //prev = currNode
        currNode = nextNode
    }

    p := prev
    for p != nil {
        fmt.Print(p.data, " ")
        p = p.next
    }

    return prev

}
func (l *Slink) sort() {
    var a []int
    p := l.tail
    for p != nil {
        a = append(a, p.data)
        p = p.next
    }
    sort.Ints(a)
    newNode := &amp;amp;Node{}
    s := newNode
    for _, v := range a {
        s.next = &amp;amp;Node{data: v}
        s = s.next
    }
    q := newNode.next
    for q != nil {
        fmt.Print(q.data, " ")
        q = q.next
    }

}
func (l *Slink) display() {
    p := l.head
    for p != nil {
        fmt.Print(p.data, " ")
        p = p.next
    }

}
func disp(n *Node) {
    for n != nil {
        fmt.Print(n.data, " ")
        n = n.next
    }

}

func main() {
    l := Slink{}
    l.append(20)
    l.append(10)
    l.append(2)
    l.append(3)
    l.append(4)
    l.append(60)
    l.push(70, 5)
    l.pop(7)
    l.display()
    fmt.Println()
    fmt.Println()
    // b := l.Reverse()
    // disp(b)
    // fmt.Println("")
    // l.sort()
    l.Reverse()

}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Doubly Linked List in golang&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;package main

import "fmt"

type Node struct {
    data int
    next *Node
    prev *Node
}
type Dlink struct {
    head *Node
    tail *Node
}

func (l *Dlink) append(n int) {
    newNode := &amp;amp;Node{data: n}
    if l.head == nil {
        l.head = newNode
    } else {
        l.tail.next = newNode
        newNode.prev = l.tail
    }
    l.tail = newNode
}

func (l *Dlink) push(n int, pos int) {
    if pos == 0 {
        newNode := &amp;amp;Node{data: n}
        temp := l.head
        l.head.prev = newNode
        newNode.next = temp
        l.head = newNode
    } else if pos &amp;gt; 0 &amp;amp;&amp;amp; pos &amp;lt; l.len()-1 {
        newNode := &amp;amp;Node{data: n}
        temp := l.head
        i := 0
        for i &amp;lt; pos-1 {
            temp = temp.next
            i += 1
        }
        newNode.prev = temp
        newNode.next = temp.next
        temp.next.prev = newNode
        temp.next = newNode
    } else {
        newNode := &amp;amp;Node{data: n}
        temp := l.tail
        newNode.prev = temp
        temp.next = newNode
        l.tail = newNode

    }
}

func (l *Dlink) pop(pos int) {
    if pos == 0 {
        temp := l.head
        l.head = temp.next
        l.head.prev = nil
        temp.next = nil
    } else if pos &amp;gt; 0 &amp;amp;&amp;amp; pos &amp;lt; l.len()-1 {
        p := l.head
        i := 0
        for i &amp;lt; pos-1 {
            p = p.next
            i += 1
        }
        temp := p.next
        p.next = temp.next
        temp.next.prev = temp
        temp.next = nil
        temp.prev = nil
    } else {
        temp := l.tail
        l.tail = l.tail.prev
        l.tail.next = nil
        temp.prev = nil
        temp.next = nil
    }
}
func (l *Dlink) len() int {
    p := l.head
    count := 0
    for p != nil {
        count++
        p = p.next
    }
    return count

}

func (l *Dlink) reverce() {
    var prev *Node
    cuurentNode := l.head
    nextNode := l.head
    for nextNode != nil {
        nextNode = nextNode.next
        cuurentNode.next = prev
        prev = cuurentNode
        cuurentNode = nextNode
    }
    // temp := l.head
    l.head, l.tail = l.tail, l.head
    // l.tail = temp
    p := prev
    fmt.Println(l.head.data)
    for p != nil {
        fmt.Print(p.data, " ")
        p = p.next
    }
    fmt.Println("")
    fmt.Println(l.tail.data)

}
func (l *Dlink) display() {
    p := l.head
    fmt.Println(l.head.data)
    for p != nil {
        fmt.Print(p.data, " ")
        p = p.next
    }
    fmt.Println("")
    fmt.Println(l.tail.data)
}
func main() {
    l := Dlink{}
    l.append(10)
    l.append(20)
    l.append(30)
    l.append(40)
    l.append(50)
    l.append(60)
    l.push(200, 6)
    l.reverce()

}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Circular Linked List in golang&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;package main

import (
    "fmt"
)

type Node struct {
    data int
    next *Node
}

type slinkh struct {
    tail *Node
}

func (l *slinkh) creat(n int) {
    newNode := &amp;amp;Node{data: n}
    if l.tail == nil {
        l.tail = newNode
        l.tail.next = newNode
    } else {
        newNode.next = l.tail.next
        l.tail.next = newNode
        l.tail = newNode
    }

}

func (l *slinkh) push(n int, pos int) {
    if pos == 0 {
        newNode := &amp;amp;Node{data: n}
        newNode.next = l.tail.next
        l.tail.next = newNode
    } else if pos &amp;gt;= l.len() {
        newNode := &amp;amp;Node{data: n}
        newNode.next = l.tail.next
        l.tail.next = newNode
        l.tail = newNode
    } else if pos &amp;gt; 0 &amp;amp;&amp;amp; pos &amp;lt; l.len() {
        newNode := &amp;amp;Node{data: n}
        i := 1
        p := l.tail
        for i &amp;lt; pos {
            p = p.next
            i += 1
        }
        newNode.next = p.next
        p.next = newNode
    }
}

func (l *slinkh) pop(pos int) {
    if pos == 0 {
        temp := l.tail.next.next
        l.tail.next = temp
        temp = nil
        // fmt.Println("")
        // fmt.Println(l.tail.next.next.data)
    } else if pos &amp;gt;= l.len()-1 {
        p := l.tail
        for p.next.next != l.tail {
            p = p.next
        }
        temp := l.tail.next
        p.next.next = temp
        l.tail = p.next
        temp = nil
    } else if pos &amp;gt; 0 &amp;amp;&amp;amp; pos &amp;lt; l.len() {
        p := l.tail
        i := 1
        for i &amp;lt; pos {
            p = p.next
            i += 1
        }
        temp := p.next.next
        p.next.next = temp.next
        temp.next = nil
    }
}

func (l *slinkh) len() int {
    temp := l.tail
    count := 1
    for l.tail != temp.next {
        count += 1
        temp = temp.next
    }
    return count
}

func (l *slinkh) reverse() {
    var prev, currNode, nextNode *Node
    currNode = l.tail.next
    nextNode = currNode.next
    for currNode != l.tail {
        prev = currNode
        currNode = nextNode
        nextNode = currNode.next
        currNode.next = prev
    }
    nextNode.next = l.tail
    l.tail = nextNode
    p := l.tail
    temp := l.tail
    for l.tail != temp.next {
        temp = temp.next
        fmt.Print(temp.data, " ")
    }
    fmt.Print(p.data)
}

func (l *slinkh) disp() {
    p := l.tail
    temp := l.tail
    for l.tail != temp.next {
        temp = temp.next
        fmt.Print(temp.data, " ")
    }
    fmt.Print(p.data)

}

func main() {
    l := slinkh{}
    l.creat(10)
    l.creat(20)
    l.creat(30)
    l.creat(40)
    l.creat(50)
    // l.push(100, 1)
    // l.push(300, 6)
    // l.pop(4)
    l.reverse()
    // l.disp()
    // b := l.len()
    // fmt.Println("")
    // fmt.Println(b)

}

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
    </item>
    <item>
      <title>sorting golang</title>
      <dc:creator>vinay</dc:creator>
      <pubDate>Wed, 07 Sep 2022 06:38:14 +0000</pubDate>
      <link>https://forem.com/vinaygo/sorting-golang-49nd</link>
      <guid>https://forem.com/vinaygo/sorting-golang-49nd</guid>
      <description>&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;package main

import (
    "fmt"
    "math"
)

func LinearSarch(a []int, key int) string {
    point := 0
    for point &amp;lt; len(a) {
        if key == a[point] {
            return fmt.Sprintf("found the index is %d", point)
        }
        point += 1
    }
    return "Not found Index"

}

func BinarySarch(a []int, key int, Left int, Right int) string {
    if Left &amp;lt;= Right {
        midPoint := int(math.Floor(float64(Left+Right) / 2))
        if key == a[midPoint] {
            return fmt.Sprintf("found the index is %d", midPoint)
        } else if key &amp;lt; a[midPoint] {
            return BinarySarch(a, key, Left, midPoint-1)
        } else {
            return BinarySarch(a, key, midPoint+1, Right)
        }
    }
    return "Not found"

}

func selection(a []int) {
    for i := 0; i &amp;lt; len(a)-1; i++ {
        min := i
        for j := i + 1; j &amp;lt; len(a); j++ {
            if a[j] &amp;lt; a[min] {
                min = j
            }
        }
        temp := a[i]
        a[i], a[min] = a[min], temp
    }

}

func insertion(a []int) {
    for i := 1; i &amp;lt; len(a); i++ {
        temp := a[i]
        j := i - 1
        for j &amp;gt;= 0 &amp;amp;&amp;amp; a[j] &amp;gt; temp {
            a[j+1] = a[j]
            j--
        }
        a[j+1] = temp

    }

}

func bubblesort(a []int) {
    for i := 0; i &amp;lt; len(a)-1; i++ {
        for j := 0; j &amp;lt; len(a)-1-i; j++ {
            if a[j] &amp;gt; a[j+1] {
                temp := a[j]
                a[j] = a[j+1]
                a[j+1] = temp
            }
        }

    }

}

func sellsort(arr []int, n int) {
    for gap := n / 2; gap &amp;gt; 0; gap = gap / 2 {
        for j := gap; j &amp;lt; n; j++ {
            for i := j - gap; i &amp;gt;= 0; i -= gap {
                if arr[i+gap] &amp;gt; arr[i] {
                    break
                } else {
                    temp := arr[i]
                    arr[i] = arr[i+gap]
                    arr[i+gap] = temp
                }

            }

        }
    }

}
func partition(arr []int, lb int, ub int) int {
    pivot := arr[lb]
    start := lb
    end := ub
    for start &amp;lt; end {
        if arr[start] &amp;lt;= pivot {
            start += 1
        }
        for arr[end] &amp;gt; pivot {
            end -= 1
        }
        if start &amp;lt; end {
            temp := arr[start]
            arr[start] = arr[end]
            arr[end] = temp
         }
    }
    temp := arr[lb]
    arr[lb] = arr[end]
    arr[end] = temp
    return end
}

func quikSort(arr []int, lb int, ub int) {
    if lb &amp;lt; ub {
        p := partition(arr, lb, ub)
        quikSort(arr, lb, p-1)
        quikSort(arr, p+1, ub)
    }
}

func main() {
    a := []int{10, 20, 30, 10, 5, 3, 2}
    bubblesort(a)
    sellsort(a, len(a))
    insertion(a)
    selection(a)
    fmt.Println(a)
    b := BinarySarch(a, 30, 0, len(a)-1)
    q := LinearSarch(a, 30)
    fmt.Println(b, q)

}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
      <category>go</category>
    </item>
    <item>
      <title>LinearSearch Golang</title>
      <dc:creator>vinay</dc:creator>
      <pubDate>Tue, 06 Sep 2022 11:03:41 +0000</pubDate>
      <link>https://forem.com/vinaygo/linearsearch-golang-1a2n</link>
      <guid>https://forem.com/vinaygo/linearsearch-golang-1a2n</guid>
      <description>&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;package main

import (
    "fmt"
    "strconv"
)

func LinearSearch(a []int, k int) string {
    i := 0
    for i &amp;lt; len(a) {
        if a[i] == k {
            return "Found" + " index is " + strconv.Itoa(i)
        }
        i += 1
    }
    return "Not found index"

}

func main() {
    a := []int{10, 20, 30, 40, 50}
    fmt.Println(LinearSearch(a, 50))

}

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
      <category>go</category>
    </item>
    <item>
      <title>Linked list golang and python</title>
      <dc:creator>vinay</dc:creator>
      <pubDate>Mon, 05 Sep 2022 10:13:14 +0000</pubDate>
      <link>https://forem.com/vinaygo/linked-list-golang-and-python-37me</link>
      <guid>https://forem.com/vinaygo/linked-list-golang-and-python-37me</guid>
      <description>&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;class Node:
    def __init__(self,value):
        self.value = value
        self.adress=None
# creating a head and tail
class linkedList:
    def __init__(self):
        self.head=None
        self.tail=None
        self.size=0


    def addvalue(self,v):
        newest=Node(v)
        if self.size==0:
            self.head=newest
        else:
            self.tail.adress=newest
        self.tail=newest
        self.size+=1
    def addfirst(self, e):
        newest = Node(e)
        if self.size==0:
            self.head = newest
            self.tail = newest
        else:
            newest.adress= self.head
            self.head = newest
    def addany(self, e, position):
        newest = Node(e)
        p = self.head
        i = 1
        while i &amp;lt; position-1:
            p = p.adress
            i = i + 1
        newest.adress = p.adress
        p.adress = newest
        self.size += 1


    def display(self):
        print("head val:",self.head.value)
        p=self.head
        while p:
            print(p.value,end=" ")
            p=p.adress
        print()
        print("tail val: ",self.tail.value)


l=linkedList()
l.addvalue(10)
l.addvalue(20)
l.addvalue(30)
l.addvalue(40)
l.addvalue(50)
l.addvalue(60)
l.addany(70,3)
l.addfirst(80)
l.addfirst(90)
l.display()
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;package main

import (
    "fmt"
)

type Node struct {
    value  interface{}
    adress *Node
}

type List struct {
    head *Node
    tail *Node
    size int
}

func (l *List) Insert(d interface{}) {
    list := &amp;amp;Node{value: d, adress: nil}
    if l.size == 0 {
        l.head = list
    } else {
        l.tail.adress = list
    }
    l.tail = list
    l.size++
}

func (l *List) addfirst(d interface{}) {
    list := &amp;amp;Node{value: d, adress: nil}
    if l.size == 0 {
        l.head = list
        l.tail = list
    } else {
        list.adress = l.head
        l.head = list
    }
}

func (l *List) addany(d interface{}, position int) {
    list := &amp;amp;Node{value: d, adress: nil}
    p := l.head
    i := 1
    for i &amp;lt; position-1 {
        p = p.adress
        i = i + 1
    }
    list.adress = p.adress
    p.adress = list
    l.size += 1

}

func (l *List) display() {
    p := l.head
    fmt.Println(l.head.value)
    for p != nil {
        fmt.Print(p.value, " ")
        p = p.adress
    }
    fmt.Println()
    fmt.Print(l.tail.value)
    fmt.Println("")
    fmt.Print(l.size)
}

func main() {
    link := List{}
    link.Insert(5)
    link.Insert(9)
    link.Insert(13)
    link.Insert(22)
    link.Insert(28)
    link.Insert(36)
    link.addany(70, 3)
    link.addfirst(80)
    link.display()
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
      <category>go</category>
      <category>python</category>
      <category>dsa</category>
    </item>
  </channel>
</rss>
