Code Monkey home page Code Monkey logo

bstsort's Introduction

bstsort

This program creates a binary search tree in C, then, taking input from stdin or a file, reads lines and organizes each line in ASCII order using the tree. It then outputs each line to stdout or a file, with a count next to each line signifying how many times it was found in the input.

bstsort was created as part of an assignment and is meant to be used as an educational code reference, i.e. to see an example of how a very basic binary search tree works in C.

It is by no means the most optimal or efficient way to create a binary search tree structure; the code within is mostly aimed at being readable by beginners to give them a working example of basic concepts of C, such as Makefiles, recursion, pass-by-pointer and structs.

Usage

usage: bstsort [-c] [-o output_file] [input_file]

Arguments

  • -c: sort lines, taking case into account (default behavior is case-insensitive.
  • -o: output line to file instead of stdout. If output_file does not exist, it will be created.
  • input_file: optional; if specified, lines will be read from file at input_file instead of stdin.

Running

bstsort can be run by cloning this repository into a local folder and running make (most easily done on Linux). Make sure you have a C compiler installed already; gcc is a good choice.

Sample Files

A couple of test files are included for convenience. testfile is a list of 500 randomly generated words (using randomlists.com) and testfile_sentences is a list of 100 randomly generated sentences (using randomwordgenerator.com).

Sample build and run:

git clone https://gitlab.com/mtaylor76/bstsort.git
cd bstsort
make
./bstsort testfile

Sample output:

2 apple
1 banana
1 laptop
2 xylophone
1 zebra

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.