Code Monkey home page Code Monkey logo

parity's Introduction

ParityArray Implementation

This project involves implementing a special type of array, named ParityArray, which stores integers such that all even numbers are positioned at the beginning of the array, and all odd numbers are positioned at the end. This README provides an overview of the implementation, including the base tasks, heap usage, modularization, and I/O handling.

Project Structure

  • ParityArray Struct: Contains a dynamically allocated array, even_idx, and odd_idx.
  • Functions:
    • init(): Initializes the ParityArray.
    • insert(): Inserts integers into the array in the correct position.
    • print(): Prints the contents of the array.
    • destruct(): Deallocates the underlying array.
    • dump(): Writes the array elements to a text file.

Base Task

  1. ParityArray Struct:

    • Contains a fixed-size array (initially defined by ARRAY_SIZE macro, value 10).
    • Contains two integers: even_idx and odd_idx.
  2. Functions:

    • init(): Initializes the ParityArray, setting even_idx to 0 and odd_idx to ARRAY_SIZE-1.
    • insert(): Inserts integers into their respective positions based on parity.
    • print(): Prints only the inserted elements of the array.

Heap Usage

  • Modify ParityArray to contain a pointer to a dynamically allocated array.
  • Modify init() to allocate this array on the heap, with the size provided as a parameter.
  • Implement destruct() to deallocate the array.

Modularization

  • Separate the functions into different source files.
  • Create corresponding header files with the struct definition and function declarations.
  • Implement header guards in the header files.

I/O Handling

  • Read a number from the keyboard to determine the size of the ParityArray.
  • Read that many integers from the user and insert them into the ParityArray.
  • Implement dump() to write the array elements to a text file.

Usage

  1. Initialize a ParityArray.
  2. Insert integers based on their parity.
  3. Print the array.
  4. Dump the array contents to a file.
  5. Deallocate the array when done.

parity's People

Contributors

masatonaut avatar

Watchers

 avatar

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.