Giter Site home page Giter Site logo

blasanka / data-structures Goto Github PK

View Code? Open in Web Editor NEW
2.0 2.0 0.0 33 KB

You will find this repo useful for to understand how basic Data Structures and Algorithms can be implemented using Java. Note: this is not containing Java generics features and Java 8, 9, 10 features because main purpose is not to focus in specific language(anyone can use same logic to other languages only the syntax differ)

Java 100.00%
java data-structures algorithms

data-structures's Introduction

Data Structures using Java

Note:

This repository updates everyday, check for updates and suggest anything.

How to run:

Download or clone the repository import to your favorite IDE and open any Main classes, then, you can run and check.


Content:

1. Stack

  • Provide Last In First Out(LIFO)
  • Lastly added value will remove first.
  • Example: When you press few keys on keyboard they are adding to a stack and when you press delete key lastly added value will remove first.

2. Queue (Linear Queue and Circular Queue)

  • Provide First In First Out(FIFO)
  • Firstly added value will remove first.
  • Example: This is like a persons in a queue to get meds or something in real life, firstly came person will get meds first.

2. LinkedList

  • Linked objects. Just like a simple class and properties/variables with a special property called --next to hold another Link/object memory address(In Java actually we don't have memory address rather we have hash code(example: #342ff3) for every object to uniquely identify that object.).
  • [more info coming soon.]

How to Contribute:

Star the repo then Fork it and add/change and pull request. Then, I will review and merge it. send a mail to [email protected]

data-structures's People

Contributors

blasanka avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar

data-structures's Issues

insertion sort

a = [3, 7, 4, 1, 8]

for index in range(1,len(a)):
    current = a[index]
    i = index

    while i>0 and a[i-1] > current:
        a[i] = a[i-1]
        i = i -1

    a[i] = current



print(a)

#lab session-------------------

A = []

for v in range(10):
    A.append(input('Enter a number: '))

print('\nunsorted array')
print A

def insertionSort(A):
    for j in range(1, len(A)):
        key = A[j]
        i = j - 1

        while(i >= 0 and A[i] > key):
            A[i+1] = A[i]
            i = i-1
        A[i+1] = key

insertionSort(A)

print('\nsorted array')
print(A)

print('\nsorted array elemenet by element')
for i in range(len(A)):
    print(A[i])

selection sort

def selectionSort(A):
    for j in range(len(A)):
        min = j
        for i in range(j+1,len(A)):
            if A[min] > A[i]:
                min = i
        temp = A[j]
        A[j] = A[min]
        A[min] = temp


arr = [1, -9, 3, 7]
selectionSort(arr)
print(arr)

quicksort

def partition(A, low, high):
    pivot = A[high]
    i = low -1
    for j in range(low, high):
        if A[j] <= pivot:
            i = i + 1
            A[i], A[j] = A[j], A[i]
    A[i + 1], A[high] = A[high], arr[i + 1]
    return i + 1


def quickSort(A, low, high):
    if low < high:
        q = partition(A, low, high)
        quickSort(A, low, q-1)
        quickSort(A, q+1, high)

arr = [20,51,11,1]
quickSort(arr, 0, len(arr)-1)
print(arr)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.