A Joint Algorithm for Resource Allocation in D2D 5G Wireless Networks