University Repository: https://github.cs.huji.ac.il/shirazmarom/ex2_bonus.git
Public Repository: https://github.com/Shiraz-Tehila-Marom/ai-c-python-project.git
This repository contains the ctypes bindings and extensions for the Bus Line Sorting assignment. It integrates the high-performance sorting algorithms written in C with a clean Python interface, provides an educational console memory visualizer for pointer arithmetic, and extends the project with an interactive Moovit-inspired routing GUI.
- Library Compilation: The original C sorting logic (
sort_bus_lines.c) is compiled into a shared library (libsort_bus_lines.so) with no modifications. - Wrapper Module (
bus_sort_module.py):- Maps the C
BusLinestructure andSortTypeenum to C-compatiblectypesdata structures. - Implements
bubble_sort(lexicographical sorting by name) andquick_sort(numerical sorting by distance, duration, or frequency). - Validates inputs, handles Unicode conversions, and marshals Python dictionary lists to C structures.
- Preserves exact pointer boundaries matching the C backend's
&lines[n-1]endpoint layout.
- Maps the C
- Automated Tests (
test_bus_sort.py): Includes apytestsuite validating sort correctness, boundary/edge conditions, and argument types.
- Simulates how
bubble_sortandquick_sortnavigate through array slots in memory using pointers. - Uses the 3-element dataset
["Dan", "Alice", "Charlie"]and displays fake memory addresses (0x1000,0x1040,0x1080). - Generates step-by-step memory layout diagrams indicating where pointers (
start,end/pivot,smaller_ptr,p) point at each pass and loop comparison.
- Moovit Styling: Implements a dark slate, orange, and green themed transit dashboard using Python's native
tkinterlibrary. - C Backend Integration: Interfaces directly with
bus_sort_module.pyto sort transit options in real-time using compiled C algorithms. - Vector Transit Map: A custom vector map engine running on a
tkinter.Canvasdisplaying grid roads, green parks, a river, and active starting nodes. - Route Animation: Animates a transit marker dot moving step-by-step from the selected starting district along coordinates to the University.
- Travel Instructions: Displays a structured instruction card panel showing navigation directions.
├── main.c # Original C assignment entry point
├── sort_bus_lines.c # C sorting algorithms (Bubble & Quick Sort)
├── sort_bus_lines.h # C function declarations and structures
├── libsort_bus_lines.so # Compiled C shared library
├── bus_sort_module.py # Python ctypes binding layer and wrapper functions
├── gui_app.py # Moovit-styled Python GUI application
├── visualizer.c # Standalone C program for pointer visualization
├── test_bus_sort.py # Pytest verification suite
├── test_fib.py # Pytest for Fibonacci ctypes basics
├── fib_module.py # Basic Fibonacci ctypes example
└── README.md # Project documentation
Ensure you are working inside a Linux environment (such as WSL on Windows) with gcc, make, and python3 installed.
Compile sort_bus_lines.c into the .so shared library:
gcc -shared -o libsort_bus_lines.so -fPIC sort_bus_lines.cVerify Python bindings and ctypes marshalling using pytest:
python3 -m pytest test_bus_sort.pyCompile and run the educational pointer visualizer:
gcc visualizer.c -o visualizer && ./visualizerRun the interactive Python interface (ensure X11 or WSLg is enabled if running inside WSL):
python3 gui_app.py